I didn't find something helping me in the web so i'll ask you for help.
I try sending a Message with several line breaks.
e.g.:
Hey!
Welcome to the channel!
So my code:
int main(){
CURL *handle
handle = curl_easy_init();
string url = "https://api.telegram.org/<bottoken>/sendMessage?chat_id-idnbr&text=Hey\nwhatsup"
curl_easy_setopt(handle , CURLOPT_URL, url.c_str());
curl_easy_perform(handle);
}
Now if i set it like this i get the CURLcode 3 CURL_URL_MALFORMAT (URL not formatted right)
Any idea what to do?
Related
I have been trying to upload an image in chunks with client side streaming using grpcurl. The service is working without error except that at the server, image data received is 0 bytes.
The command I am using is:
grpcurl -proto image_service.proto -v -d # -plaintext localhost:3010 imageservice.ImageService.UploadImage < out
This link mentions that the chunk data should be base64 encode and so the contents of my out file are:
{"chunk_data": "<base64 encoded image data>"}
This is exactly what I am trying to achieve, but using grpcurl.
Please tell what is wrong in my command and what is the best way to achieve streaming via grpcurl.
I have 2 more questions:
Does gRPC handles the splitting of data into chunks?
How can I first send a meta-data chunk (ImageInfo type) and then the actual image data via grpcurl?
Here is my proto file:
syntax = "proto3";
package imageservice;
import "google/protobuf/wrappers.proto";
option go_package = "...";
service ImageService {
rpc UploadImage(stream UploadImageRequest) returns (UploadImageResponse) {}
}
message UploadImageRequest {
oneof data {
ImageInfo info = 1;
bytes chunk_data = 3;
};
}
message ImageInfo {
string unique_id = 1;
string image_type = 2;
}
message UploadImageResponse {
string url = 1;
}
Interesting question. I've not tried streaming messages with (the excellent) grpcurl.
The documentation does not explain how to do this but this issue shows how to stream using stdin.
I recommend you try it that way first to ensure that works for you.
If it does, then bundling various messages into a file (out) should also work.
Your follow-on questions suggest you're doing this incorrectly.
chunk_data is the result of having split the file into chunks; i.e. each of these base64-encoded strings should be a subset of your overall image file (i.e. a chunk).
your first message should be { "info": "...." }, subsequent messages will be { "chunk_data": "<base64-encoded chunk>" } until EOF.
I tried creating a method in Postman and got really close but am having issues with the signature. We are trying to query the IP ranges for VPCs to add to a WAF rule, in order to allow traffic to a secure application.
Postman allows a pre-request script, in Javascript, and supports a handful of included JS libraries, including CryptoJS.
The code here creates exactly the request that Ali Cloud says needs to be signed. It signs with HMAC-SHA1 from CryptoJS and encodes to base 64.
All of the variables are included in the request parameters. I'm not sure what else it could be complaining about.
var dateIso = new Date().toISOString();
var randomString = function(length) {
var text = "";
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
for(var i = 0; i < length; i++) {
text += possible.charAt(Math.floor(Math.random() * possible.length));
}
return text;
}
var accesskeyid = "LTAI4GC7VEijsm5bV3zwcZxZ"
var action = "DescribePublicIPAddress"
var format = "XML"
var regionid = "cn-shanghai-eu13-a01"
var signaturemethod = "HMAC-SHA1"
var signaturenonce = randomString(16)
var signatureversion = "1.0"
var timestamp = dateIso.replace(/:/gi, "%253A")
var version = "2016-04-28"
pm.environment.set("AccessKeyId", accesskeyid)
pm.environment.set("Action", action)
pm.environment.set("Format", format)
pm.environment.set("RegionID", regionid)
pm.environment.set("SignatureMethod", signaturemethod)
pm.environment.set("SignatureNonce", signaturenonce)
pm.environment.set("SignatureVersion", signatureversion)
pm.environment.set("Timestamp", dateIso)
pm.environment.set("Version", version)
var request = "GET&%2F&" + "AccessKeyID%3D" + accesskeyid + "%26Action%3D" + action + "%26Format%3D" + format + "%26RegionID%3D" + regionid + "%26SignatureMethod%3D" + signaturemethod + "%26SignatureNonce%3D" + signaturenonce + "%26SignatureVersion%3D" + signatureversion + "%26Timestamp%3D" + timestamp + "%26Version%3D" + version
pm.environment.set("Request", request)
var hash = CryptoJS.HmacSHA1(request, "spwH5dNeEm4t4dlpqvYWVGgf7aEAxB&")
var base64 = CryptoJS.enc.Base64.stringify(hash)
var encodesig = encodeURIComponent(base64)
pm.environment.set("Signature", encodesig);
console.log(base64)
console.log(request)
The console output shows:
Signature: XbVi12iApzZ0rRgJLBv0ytJJ0LY=
Parameter string to be signed:
GET&%2F&AccessKeyID%3DLTAI4GC7VEijsm5bV3zwcZvC%26Action%3DDescribePublicIPAddress%26Format%3DXML%26RegionID%3Dcn-shanghai-eu13-a01%26SignatureMethod%3DHMAC-SHA1%26SignatureNonce%3DiP1QJtbasQNSOxVY%26SignatureVersion%3D1.0%26Timestamp%3D2020-06-01T15%253A38%253A12.266Z%26Version%3D2016-04-28
Request sent:
GET https://vpc.aliyuncs.com/?AccessKeyID=LTAI4GC7VEijsm5bV3zwcZvC&Action=DescribePublicIPAddress&Format=XML&RegionID=cn-shanghai-eu13-a01&SignatureMethod=HMAC-SHA1&SignatureNonce=iP1QJtbasQNSOxVY&SignatureVersion=1.0&Timestamp=2020-06-01T15:38:12.266Z&Version=2016-04-28&Signature=XbVi12iApzZ0rRgJLBv0ytJJ0LY%3D
Response Received:
<?xml version='1.0' encoding='UTF-8'?><Error><RequestId>B16D216F-56ED-4D16-9CEC-633C303F2B61</RequestId><HostId>vpc.aliyuncs.com</HostId><Code>IncompleteSignature</Code><Message>The request signature does not conform to Aliyun standards. server string to sign is:GET&%2F&AccessKeyID%3DLTAI4GC7VEijsm5bV3zwcZvC%26Action%3DDescribePublicIPAddress%26Format%3DXML%26RegionID%3Dcn-shanghai-eu13-a01%26SignatureMethod%3DHMAC-SHA1%26SignatureNonce%3DiP1QJtbasQNSOxVY%26SignatureVersion%3D1.0%26Timestamp%3D2020-06-01T15%253A38%253A12.266Z%26Version%3D2016-04-28</Message><Recommend><![CDATA[https://error-center.aliyun.com/status/search?Keyword=IncompleteSignature&source=PopGw]]></Recommend></Error>
When I check the "server string to sign" from the response and the parameter string that was signed in a compare, they are identical.
It looks like everything is built as needed but the signature is still barking. Guessing I missed something simple but haven't found it yet.
Note: The accesskeyID and key posted are for example purposes and not a real account so this code will not copy and paste to execute in Postman.
PS - I learned quite a bit from the other few threads on this topic, which is how I got to this point. akostadinov was super helpful on another thread.
I believe you have double encoded &. I have implemented other Alibaba Cloud REST APIs successfully. Could you please check this.
Following is the expected string to sign format:
GET&%2F&AccessKeyId%3Dtestid&Action%3DDescribeVpcs&Format%3DXML&
SignatureMethod%3DHMAC-SHA1&SignatureNonce%3D3ee8c1b8-83d3-44af-a94f-4e0ad82fd6cf&SignatureVersion%3D1.0&TimeStamp%3D2016-02-23T12%253A46%
253A24Z&Version%3D2014-05-15
A bit late to the party, but as this is the first result when googling for the IncompleteSignature error, I thought I might comment and hopefully save someone else the grief I have been through.
For me, the subtle detail that I missed in the official documentation here is that the key used for the signature requires an ampersand & to be added to the end, before being used.
As soon as I caught that, everything else worked perfectly.
I am sending the following request with one parameterization parameter ${id} and request looks like
Actual Message:
{"Data":"{\"Source\":\"#include <stdio.h>\\nint main()\\n{\\nint n;\\nprintf(\\\"Enter an integer\\\");\\nscanf(\\\"%d\\\", &n);\\nif (n%2 == 0)\\nprintf(\\\"Even\\\");\\nelse\\nprintf(\\\"Odd\\\");\\nreturn 0;\\n}\",\"Lang\":\"c\",\"callback_url\":\"callback_url_string\",\"cid\":\"159:60719:2667:${id}\"}","Action":"compile","TenantId":"159","UserId":"0","CID":"159:60719:2667:${id}","LanguageId":"25331"}
But while sending the request JMETER is altering the request (removing the few formats like \'s) and sends to the server and server responds with bad request response.
JMETER Sends like:
{"Data":"{\"Source\":\"#include <stdio.h>\nint main()\n{\nint n;\nprintf(\\"Enter an integer\\");\nscanf(\\"%d\\", &n);\nif (n%2 == 0)\nprintf(\\"Even\\");\nelse\nprintf(\\"Odd\\");\nreturn 0;\n}\",\"Lang\":\"c\",\"callback_url\":\"callback_url_string\",\"cid\":\"159:60719:2667:558019\"}","Action":"compile","TenantId":"159","UserId":"0","CID":"159:60719:2667:558019","LanguageId":"25331"}
IF you send above request without parameterization (enter values) then it works fine.
Please let me know how to resolve this issue.
I am assuming this is a POST HTTP request and the body section has this data
could you please point the HTTP body to below relative path starts from bin directory
${__eval(${__FileToString(path/to/payloadfile.txt,,)})}
Now payloadfile.txt can have the actual content still it will evaluate ${ID} and further variables as well.
if that helps dont forget to click answered. Happy to help, Happy Testing
REFINE:
I have used online tools :
first to see the data in the fisrt place is a proper one https://jsonformatter.curiousconcept.com/
I see this
{
"Data":{
"Source":"#include <stdio.h\/>\r\n int main()\r\n {\r\n int n;\r\n printf(\"Enter an integer\");\r\n scanf(\"%d\", &n);\r\n if (n%2 == 0)\r\n printf(\"Even\");\r\n else\r\n printf(\"Odd\");\r\n return 0;\r\n "
},
"Lang":"c",
"callback_url":"callback_url_string",
"cid":"159:60719:2667:${id}",
"Action":"compile",
"TenantId":"159",
"UserId":"0",
"CID":"159:60719:2667:${id}",
"LanguageId":"25331"
}
I separated out C program alone
#include <stdio.h/>
int main()
{
int n;
printf("Enter an integer");
scanf("%d", &n);
if (n%2 == 0)
printf("Even");
else
printf("Odd");
return 0;
}
and applied escape characters using online tool [applied java script escape]
http://www.freeformatter.com/javascript-escape.html#ad-output
output:
#include <stdio.h\/>\r\n int main()\r\n {\r\n int n;\r\n printf(\"Enter an integer\");\r\n scanf(\"%d\", &n);\r\n if (n%2 == 0)\r\n printf(\"Even\");\r\n else\r\n printf(\"Odd\");\r\n return 0;\r\n }
this the one i used and it shown valid json document. if you are not sending valid json document server will throw error. do not select encoding in HTTP sampler
I am building an iOS app with Swift2.0, XCode 7.2
I am trying to make an api call to:
htttp://xyz.com/t/restaurants-us?KEY=someKey&filters={"locality":{"$eq":"miami"}}
let endPoint:String = "htttp://xyz.com/t/restaurants-us?KEY=someKey&filters={%22locality%22:{%22$eq%22:%22miami%22}}"
When I try to create an URL using this string(endPoint):
let url = NSURL(string: endPoint), a nil is returned.
So I tried encoding the string before trying to create URL:
let encodedString = endPoint.stringByAddingPercentEncodingWithAllowedCharacters(NSCharacterSet.URLQueryAllowedCharacterSet())
Now the encodedString:
"htttp://xyz.com/t/restaurants-us?KEY=someKey&filters=%7B%2522locality%2522:%7B%2522$eq%2522:%2522miami%2522%7D%7D"
But now when i create a NSURL session and send the request, I get an unexpected response from the server:
Reply from server:
{
"error_type" = InvalidJsonArgument;
message = "Parameter 'filters' contains an error in its JSON syntax. For documentation, please see: http://developer.factual.com.";
status = error;
version = 3;
}
So if I don't encode the string, I will not be able to create NSURL.
But if I encode and send the request, the server is not able to handle the request.
Can anyone please suggest a workaround.
When you declare endpoint, you have already percent-encoded some characters (the quotes). When you ask iOS to percent-encode it, it percent-encodes the percent-encodes. Decoding the encodedString results in:
htttp://xyz.com/t/restaurants-us?KEY=someKey&filters={%22locality%22:{%22$eq%22:%22miami%22}}
Instead, you should start with actual quotes in endpoint:
let endPoint:String = "htttp://xyz.com/t/restaurants-us?KEY=someKey&filters={\"locality\":{\"$eq\":\"miami\"}}"
I'm using libcurl as part of my software for implementing an FTP client. One thing that I must do before sending files to the FTP server is to make a connectivity check by listing the the content of the target directory (to make sure I can connect and the directory exists) as was suggested to me in this question. The problem is I don't care about the output of the listing operation, all is care is whether the connectivity test passed or failed. In case it passed I get enormous amount of text which I'd like to discard. I'm using libcurl 7.33, however in 7.15 CURLOPT_MUTE was removed and I can't understand how to discard the listing output. Is there an alternative to CURLOPT_MUTE or any other idea how discard output from curl_easy_perform?
curl_easy_setopt(m_curl, CURLOPT_USERNAME, m_ftpUsername);
curl_easy_setopt(m_curl, CURLOPT_PASSWORD, m_ftpPassword);
curl_easy_setopt(m_curl, CURLOPT_URL, m_ftpUrl);
CURLcode res = curl_easy_perform(m_curl);
Provide a CURLOPT_WRITEFUNCTION callback that simply ignores the data and returns the correct value!
BTW, MUTE never worked to "discard the listing output".
Define a callback function
size_t callbackFunction(char *ptr, size_t size, size_t nmemb, void *userdata)
{
return size * nmemb;
}
And then
curl_easy_setopt(m_curl, CURLOPT_USERNAME, m_ftpUsername);
curl_easy_setopt(m_curl, CURLOPT_PASSWORD, m_ftpPassword);
curl_easy_setopt(m_curl, CURLOPT_URL, m_ftpUrl);
curl_easy_setopt(m_curl, CURLOPT_WRITEFUNCTION, callbackFunction);
CURLcode res = curl_easy_perform(m_curl);
curl_easy_setopt(m_curl, CURLOPT_WRITEFUNCTION, 0); // return using the default callback