我试着用Postman发布我的api并且一切都很好。我也在我的Android应用程序上使用相同的凭据。
唯一必需的元素是:标题:"X-Requested-With", "XMLHttpRequest"
,并且在正文form-data
中:email:value
& password:value
。 Sresponse
字符串为'invalid-credentials'
。我正在使用JSON,POST吗?
这是我的post
方法:
public String requestLogin(final String username, final String password) {
makeNewURL("login");
Thread thread= new Thread(new Runnable() {
@Override
public void run() {
try {
HttpPost post = new HttpPost(url);
post.addHeader("X-Requested-With", "XMLHttpRequest");
json.accumulate("email", username);
json.accumulate("password", password);
StringEntity params = null;
params = new StringEntity(json.toString());
post.setEntity(params);
HttpResponse response = httpClient.execute(post);
HttpEntity entity = response.getEntity();
Sresponse=" "+ EntityUtils.toString(entity);
}
catch(Exception x){
Sresponse=x.getMessage();
}
}
});
thread.start();
return Sresponse;
}