我正在连接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);
答案 0 :(得分:0)
似乎您要解决的服务在API KEY中取决于ACTUAL值:
postParameters.add(new BasicNameValuePair("api_key", "apy_key"));
将第二个操作数替换为您给出的API键。