I have a string like "key=value" which I want to provide in my REST POST requests body. e.g.:
String content = "key=value";
Once set and trasmitted my logout output tells me, that my '=' sign content was converted to a '\u003d' wihch results in "key\u003dvalue" in my REST POST request content. Then the server responds a 400 Bad Request..
How can I prevent the '=' being converted to that unicode ?
Try this :
String content = "key\=value";
Related
I'm getting an Api response as this
X-Amz-Credential=0XCA1HQW6NU67Z1FP3U1%2F20221011%2Fus-east-1%2Fs3%2Faws4_request
But when I send this value as query parameters in the next Api, It is automatically converted into
X-Amz-Credential=0XCA1HQW6NU67Z1FP3U1%252F20221011%252Fus-east-1%252Fs3%252Faws4_request
wherever there is %2F it is converted into %252F, So the Api is failing as 400 Bad request.
You can use the encoded property of retrofit's #Query annotation to mark the value as already encoded, preventing it from being URL
encoded again.
For example:
#Query(value = "credential", encoded = true) credential: String
I think you can fix it by first decoding the original response and then sending it as a query param to next request. You can use one of the below methods for decoding:
import android.net.Uri
Uri.decode(response)
OR
import java.net.URLDecoder
URLDecoder.decode(response, "utf-8")
For response = 0XCA1HQW6NU67Z1FP3U1%2F20221011%2Fus-east-1%2Fs3%2Faws4_request,
the decoded response will be 0XCA1HQW6NU67Z1FP3U1/20221011/us-east-1/s3/aws4_request
I am using a query where I need to POST to an endpoint with okhttpclient.
The issue is I have the payload value and the senttime. I just don't know how to create a json object to send over as a raw body object to the endpoint.
To make things more clear:
here's my postman screenshot:
enter image description here
This is my post request :
https://example.org/api/service-profile/v1/device-notification/{deviceId}
Now I am planning to pass {deviceId} in the path, authorization token in the header and finally , as raw payload query like this in the body :
{
"payload": {"notificationID":"677291f5-a784-43df-af2e-0363a4067e9c","title":"test 223","body":"payload","lockScreenVisibility":1,"groupMessage":"","fromProjectNumber":"819539062812","priority":5,"rawPayload":"{\"google.delivered_priority\":\"normal\",\"google.sent_time\":1591849563191,\"google.ttl\":259200,\"google.original_priority\":\"normal\",\"custom\":\"{\\\"i\\\":\\\"677291f5-a784-43df-af2e-0363a4067e9c\\\"}\",\"oth_chnl\":\"\",\"pri\":\"5\",\"abc\":\"1\",\"from\":\"819539062812\",\"alert\":\"payload\",\"title\":\"test 223\",\"grp_msg\":\"\",\"google.message_id\":\"0:1591849563205759%409ebbcaf9fd7ecd\",\"google.c.sender.id\":\"819539062812\",\"notificationId\":-1451117355}"}
,
"sentTime": 1591849563191
}
trouble is I have the payload value and senttime, but I dont know how to construct a json object such that i can create the structure as { "payload" :pass in my payload value, "senttime":pass in sent time}
and then pass it as a raw body param over okhttpclient? Any idea how to accomplish this?
Thanks!
How can I send special character parameter in URLencoded form without change using volley library
I have to send
qty$1:23
qty$2:666
this data in URLencoded form using volley library but due to Volley Request class it is doing UTF encoding foe key value pairs.How can I avoid to change the parameter names.
Using Volley now parameters names are changed like qty%241:23 which is not acceptable by server.Please help me
Try encoding first:
String encoded = URLEncoder.encode(stringToEncode, "UTF-8"); and send the encoded string.
According to the documentation of this method:
This method uses the supplied encoding scheme to obtain the bytes for unsafe characters.
I have the following { #POST("mobile/posts/add")
Call publish(#QueryMap Map options}
Where one of the options is an encoded based64 string from bitmap image. The server side takes it as a query parameter, but retrofit keeps saying bad request. I have seen some solutions with the multipart, but those ones are not working for me. The server side takes only string query parameters, thus the post should only be sent as #query or #queryMap.
Thanks in advance
iam calling a webservice(php http get request)
http://website.com/admin/employee_login.php?fun_name=abc&company_code=1&employee_ss=123>ime=02:22 PM&x_id=350&v_id=9&task={"Walking":"1","Transfers":"1","OstomyCare":"1"}
but when am encoding this url am getting something different with %20 something like that, and it's not updating the tasks in the server database. Is there any method where i can pass parameters as a json array without encoding like same above ?
thank you
Before sending the url and parameters are url encoded. For instance spaces become %20. On the receiving side php should url decode the parameters. There is a php function which does that for you. After that you have the original parameters back.
use:
String value = "my url value"; // put here your url
URLEncoder.encode(value,"UTF-8")