I'm using retrofit for my network layer I'm facing a strange issue I've the parameter and it's value look like this
store://0TxIGQMQbObzvU4Apia0V0&callback=
and after encoding it changes to this
store://0TxIGQMQbObzvU4Apia0V0%26callback%3D
and for some reason server is not liking this encoding and I'm getting "HTTP 400 Bad Request".
If I hit without encoding it runs fine so I was wondering is there is any way i can disable the endoing.
I've tried other ways like this
@Query(value "env" encoded = false) String env
but no luck.
This is my network interface class
public interface NetworkService
{
@GET("v1/public/yql")
Observable<SeriesEntity> getOnGoingSeries(@Query("q") String query,
@Query("format") String format,
@Query("diagnostics") boolean flag,
@Query("env") String env);
class Factory {
public static NetworkService create()
{
OkHttpClient.Builder clientBuilder = new OkHttpClient.Builder();
HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
clientBuilder.addInterceptor(loggingInterceptor);
Gson gson = new GsonBuilder().disableHtmlEscaping().create();
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://query.yahooapis.com")
.client(clientBuilder.build())
.addConverterFactory(GsonConverterFactory.create())
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.build();
return retrofit.create(NetworkService.class);
}
}
}
Edit :
I also notice that the issue is only the encoded value of '&' because if i replace it value (whic is %26) it works fine
You can decode the url using javascript Function: decodeURIComponent(Url ); Because Browser encodes the Url for special characters . For example : https://www.example.com is encoded to %20https%3A%2F%2Fwww.example.com. Here the special characters are replaced by % and its ASCI value.
URLs cannot contain spaces. URL encoding normally replaces a space with a plus (+) sign or with %20.
Why do we need to encode? URLs can only have certain characters from the standard 128 character ASCII set. Reserved characters that do not belong to this set must be encoded. This means that we need to encode these characters when passing into a URL.
Annotation Type FormUrlEncodedDenotes that the request body will use form URL encoding. Fields should be declared as parameters and annotated with @Field . Requests made with this annotation will have application/x-www-form-urlencoded MIME type.
Please Use encoded = true
@Query(value = "email", encoded = true)
@HTTP(method = "DELETE", path = ApiConstant.DELETE_CONTACT_INFO, hasBody = true)
Observable deleteContactInfo( @Query(value = "email", encoded = true) String email);
the issue I believe is that you're including callback
param as part of env
one. Try adding @Query("callback") boolean callback
to your retrofit interface (and using just store://0TxIGQMQbObzvU4Apia0V0
for env
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With