Hi folks
I'm trying to develop an Android application that have to query Google Safe
Browsing for URL checking. I made several attempts but unfortunately I
always get 400-Bad Request from Safe Browsing. Does somebody have some hint
or suggestion?
I'm putting below here the method that I implemented for creating the
HTTPClient as well as the piece of source code which actually makes the
request.
Thanks in advance for suggestions.
Method which returns the HTTPClient:
private final HttpClient createHttpClient(){
HttpParams httpParams = new BasicHttpParams();
HttpProtocolParams.setVersion(httpParams, HttpVersion.HTTP_1_1);
HttpProtocolParams.setContentCharset(httpParams,
HTTP.DEFAULT_CONTENT_CHARSET);
SchemeRegistry schemeRegistry = new SchemeRegistry();
Scheme httpScheme = new
Scheme("http",PlainSocketFactory.getSocketFactory(),80);
schemeRegistry.register(httpScheme);
Scheme httpsScheme = new
Scheme("https",SSLSocketFactory.getSocketFactory(),443);
schemeRegistry.register(httpsScheme);
ClientConnectionManager tsConnManager = new
ThreadSafeClientConnManager(httpParams,schemeRegistry);
HttpClient tmpClient = new
DefaultHttpClient(tsConnManager,httpParams);
return tmpClient;
}
and here is the piece of code which makes the POST request
try {
HttpClient httpClient = createHttpClient();
String responseString = null;
HttpPost post = new HttpPost(new
URI("https://sb-ssl.google.com/safebrowsing/api/lookup?client=api&apikey=123key321&appver=1.0&pver=2.0"));
post.setEntity(new StringEntity("1/r/n"+urlToBeChecked));
HttpResponse result = httpClient.execute(post);
Log.d("MainActivity", result.getStatusLine().toString());
StatusLine statusLine = result.getStatusLine();
if(statusLine.getStatusCode() == HttpStatus.SC_OK){
ByteArrayOutputStream out = new
ByteArrayOutputStream();
result.getEntity().writeTo(out);
out.close();
responseString = out.toString();
} catch (Exception e) {
// Catch some exceptions (Actually multiple catch blocks,
shortened)
e.printStackTrace();
}
}
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en