我尝试使用继承请求的自定义请求类发送GET请求。我试过通过getParams()方法设置参数。但是当我发送请求时,我收到的用户名或密码无效错误。我不知道为什么会这样。但是当我通过包含http://myurl.com/method?user=“username”& password =“password”等参数的url发送请求时,它可以工作。有人可以告诉我为什么会这样吗?
CustomRequest request=new CustomRequest(number,url,new MyListener(number),new ErrorListner(number)){
@Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String, String> query=new HashMap<>();
query.put("user",data.getString("user"));
query.put("password",data.getString("password"));
query.put("sender",data.getString("senderid"));
query.put("SMSText",data.getString("message"));
query.put("GSM",number);
return query;
}
};
答案 0 :(得分:2)
读取javadoc,您将看到getParams仅由POST或PUT使用,而不是GET。您需要自己将查询参数添加到URL中。
/**
* Returns a Map of parameters to be used for a POST or PUT request. Can throw
* {@link AuthFailureError} as authentication may be required to provide these values.
*
* <p>Note that you can directly override {@link #getBody()} for custom data.</p>
*
* @throws AuthFailureError in the event of auth failure
*/
protected Map<String, String> getParams() throws AuthFailureError {
return null;
}