在我的当前项目中,我遇到了关于URL中的“=”和“”符号的问题。
http://mysampledomain.com/login?q='userlogin'="sample"
我尝试了一切方法。"@Path"无法工作,当我尝试使用"@Query"时,字符"="和' "'被更改为ASCII码,导致它不能正常工作。
http://mysampledomain.com/login?q%3D%userlogin%27=%22sample%22
我该如何发出这种类型的请求?
谢谢!
在我的当前项目中,我遇到了关于URL中的“=”和“”符号的问题。
http://mysampledomain.com/login?q='userlogin'="sample"
我尝试了一切方法。"@Path"无法工作,当我尝试使用"@Query"时,字符"="和' "'被更改为ASCII码,导致它不能正常工作。
http://mysampledomain.com/login?q%3D%userlogin%27=%22sample%22
我该如何发出这种类型的请求?
谢谢!
@GET
Call<ApiResponseModel> getUserDetails(@Header("Authorization") String token, @Url String fullUrl);
app.get('/login', function(req, res) {
var userLogin = req.query.userLogin;
var otherVariable = req.query.otherVariable;
// Do whatever you want.
});
使用这种方法
public static final String BASE_URL + "http://mysampledomain.com/";
public interface RetrofitClient{
@GET("login")
Call<String> login(@QueryMap Map<String, String> map);
}
调用此函数
Map<String, String> map = new HashMap<>();
map.put("userlogin", "sample");
map.put("param2", "param2");
OkHttpClient.Builder okBuilder = new OkHttpClient.Builder();
Gson gson = new GsonBuilder()
.setLenient()
.create();
Retrofit r = new Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(ScalarsConverterFactory.create())
.addConverterFactory(GsonConverterFactory.create(gson))
.client(okBuilder.build())
.build();
r.create(RetrofitClient.class).login(map).enqueue(this);
如果你的API像这样,请检查你的API URL
http://mysampledomain.com/login?userlogin=sample&otherVariable=otherValue
然后
@GET("login")
Observable<LoginResponse> getUserProductViewed(@Query("userlogin") String userlogin,@Query("otherVariable")String otherVariable);
以及基本URL,例如:
public static String BASE_URL = "http://mysampledomain.com/";
http://mysampledomain.com/login?userlogin=sample¶m2=value2
(您可以根据需要添加或删除参数)。 - MatPag