Closed ex-melody closed 2 years ago
Unirestis not postman and we don't have any intent of mimicking it's behavior but as far as I can tell Unirest is doing exactly what you are asking for and sending the param with the encoded +. If I post to http bin I get this:
String body = Unirest.get("https://httpbin.org/get?date=2022-01-09T16:05:41.041%2b08:00") .asString() .getBody();
{
"args": {
"date": "2022-01-09T16:05:41.041+08:00"
},
"headers": {
"Accept-Encoding": "gzip",
"Host": "httpbin.org",
"User-Agent": "unirest-java/3.1.00",
"X-Amzn-Trace-Id": "Root=1-6203c7b9-255616fc4bbc7f287fbf86d8"
},
"origin": "50.81.155.246",
"url": "https://httpbin.org/get?date=2022-01-09T16:05:41.041%2b08:00"
}
It looks like from your screen shot that Postman is turning your encoded value back to +, or that might be a artifact of the logger, I don't know, I don't use Postman.
One note is that your datetime isn't really properly encoded, the colons should also be encoded to make a proper URL encoded param. You can do this with formal params like this:
String body = Unirest.get("https://httpbin.org/get") .queryString("date", "2022-01-09T16:05:41.041+08:00") .asString() .getBody();
which results in
{
"args": {
"date": "2022-01-09T16:05:41.041+08:00"
},
"headers": {
"Accept-Encoding": "gzip",
"Host": "httpbin.org",
"User-Agent": "unirest-java/3.1.00",
"X-Amzn-Trace-Id": "Root=1-6203c896-44d49c2d2026bf712387fb30"
},
"origin": "50.81.155.246",
"url": "https://httpbin.org/get?date=2022-01-09T16%3A05%3A41.041%2B08%3A00"
}
Unirestis not postman and we don't have any intent of mimicking it's behavior but as far as I can tell Unirest is doing exactly what you are asking for and sending the param with the encoded +. If I post to http bin I get this:
String body = Unirest.get("https://httpbin.org/get?date=2022-01-09T16:05:41.041%2b08:00") .asString() .getBody();
{ "args": { "date": "2022-01-09T16:05:41.041+08:00" }, "headers": { "Accept-Encoding": "gzip", "Host": "httpbin.org", "User-Agent": "unirest-java/3.1.00", "X-Amzn-Trace-Id": "Root=1-6203c7b9-255616fc4bbc7f287fbf86d8" }, "origin": "50.81.155.246", "url": "https://httpbin.org/get?date=2022-01-09T16:05:41.041%2b08:00" }
It looks like from your screen shot that Postman is turning your encoded value back to +, or that might be a artifact of the logger, I don't know, I don't use Postman.
One note is that your datetime isn't really properly encoded, the colons should also be encoded to make a proper URL encoded param. You can do this with formal params like this:
String body = Unirest.get("https://httpbin.org/get") .queryString("date", "2022-01-09T16:05:41.041+08:00") .asString() .getBody();
which results in
{ "args": { "date": "2022-01-09T16:05:41.041+08:00" }, "headers": { "Accept-Encoding": "gzip", "Host": "httpbin.org", "User-Agent": "unirest-java/3.1.00", "X-Amzn-Trace-Id": "Root=1-6203c896-44d49c2d2026bf712387fb30" }, "origin": "50.81.155.246", "url": "https://httpbin.org/get?date=2022-01-09T16%3A05%3A41.041%2B08%3A00" }
same code,different result { "args": { "date": "2022-01-09T16:05:41.041%2b08:00" }, "headers": { "Accept-Encoding": "gzip", "Host": "httpbin.org", "User-Agent": "unirest-java/1.3.11", "X-Amzn-Trace-Id": "Root=1-620463a8-11c75bf1455b0aa1213bb224" }, "origin": "101.231.195.150", "url": "https://httpbin.org/get?date=2022-01-09T16:05:41.041%252b08:00" }
after update version of Unirest ,it's all fixed
Describe the bug this is my requeset " https://china-merchant.wish.com/api/v3//products/?sort_by=updated_at.asc&updated_at_min=2022-01-09T16:05:41.041%2b08:00 " i need encode the plus (+) symbol in a URL in a Get request; but this is the error message from wish api "{"message":"'2022-01-09T16:05:41.041%2b08:00' is not a 'date-time' for parameter 'updated_at_min'. Acceptable format should be like YYYY-MM-DDThh:mm:ss.sss+hh:mm","code":1003,"data":{}}"
To Reproduce Steps to reproduce the behavior:
Expected behavior this same url work in postman,so i wish it work like in postman
Screenshots
Environmental Data: