I am connecting to Restful Web Service and obtaining a JSON response.
I am able to send the request and handle the response in a JSON object,but the problem is that I receive an error:
Invalid api_key(is a parameter that I send,but I am sure is right).
Can you please help me to understand if there is a problem in my code or from 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);
Seems like the service you are addressing expectes an ACTUAL value in the API KEY: postParameters.add(new BasicNameValuePair("api_key", "apy_key"));
Replace the second operand to the APIkey you were given.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.