0

我正在连接到 Restful Web Service 并获得 JSON 响应。

我能够发送请求并处理 JSON 对象中的响应,但问题是我收到一个错误:

Invalid api_key(is a parameter that I send,but I am sure is right).

您能否帮助我了解我的代码或 WEB 是否有问题?

HttpClient httpClient = new DefaultHttpClient();
httpClient.getConnectionManager().getSchemeRegistry().register(new Scheme("SSLSocketFactory", SSLSocketFactory.getSocketFactory(), 443));
HttpPost request = new HttpPost();
request.setHeader("Content-type", "application/json, charset=utf-8");
request.setHeader("Accept", "application/json");
URI targetUri = new URI(TARGET_URL);
request.setURI(targetUri);
List<NameValuePair> postParameters = new ArrayList<NameValuePair>();
postParameters.add(new BasicNameValuePair("api_key", "api_key"));
postParameters.add(new BasicNameValuePair("user[email]", email));
postParameters.add(new BasicNameValuePair("user[password]",pwd));

Log.i("","EMAIL REQUEST: "+email.toString());
Log.i("","PWD REQUEST: "+pwd.toString());
HttpEntity postEntity = new UrlEncodedFormEntity(postParameters,"UTF-8");
request.setEntity(postEntity);
Log.i("","Request header "+request.getRequestLine());
Log.i("","Request : " +EntityUtils.toString(request.getEntity()));

httpClient.execute(request, myResponseHandler);
4

1 回答 1

0

似乎您正在处理的服务需要 API KEY 中的 ACTUAL 值: postParameters.add(new BasicNameValuePair("api_key", "apy_key"));

将第二个操作数替换为您提供的 APIkey。

于 2013-03-15T14:02:48.387 回答