Parameters not read when HTTP Secure posting in Android - java

I have an application that uses a https post to a remote server.
Everytime I attempt to post to that server I get a response that says that I have not added the id parameter.
Here is my code
HttpHost host = new HttpHost("hostname", 443, "https");
HttpPost httppost = new HttpPost(uri);
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("description", "Android"));
nameValuePairs.add(new BasicNameValuePair("type", "Android"));
nameValuePairs.add(new BasicNameValuePair("id", DeviceUtils.getID()));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs, HTTP.UTF_8));
String content = httppost.getEntity().toString();
HttpResponse response = httpclient.execute(host, httppost);
I have tried with and without the "custom" httphost, but I always get the same response.
Similar code has been used in a javaclient that runs on the desktop, and it works just fine.
The Id is the deviceId that has been RSA Encrypted and Base64 encoded.
Any ideas as to what I am doing wrong here.

Related

How do contents in name value pair pass as arguments in Android Studio?

Suppose i have this
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("pin", "date"));
And When i use the following code
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://X.X.X.X/abcdef.php");
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
what will be the post request? How will the arguments pass in the url?
found the answer
can refer this link for more details
arguments are passed as this
http://localhost/xyz.php?pin=date&package=123&requirements=xxx&last_date=25%20april

How to make Post Request using Smali code?

Need to make simple POST request with one parameter using org.apache.http.HttpRequest
in Smali code, or something like translate Java to Smali?
Code like that, but in Smali.
HttpClient httpclient = HttpClients.createDefault();
HttpPost httppost = new HttpPost("http://www.mywebsite.com");
List<NameValuePair> params = new ArrayList<NameValuePair>(1);
params.add(new BasicNameValuePair("param-1", "12345"));
httppost.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));
HttpResponse response = httpclient.execute(httppost);

Post request to server. Different responses with different defaultClients

When i try to send post request using Java (JVM on Mac) with correct credentials I got correct response code 302 FOUND.
But when using the same code on the android, with SAME correct params, i got response CODE 200 OK.
Code to send post request:
DefaultHttpClient httpclient = new DefaultHttpClient();
HttpPost httpost = new HttpPost(POST_URL);
List<NameValuePair> nvps = new ArrayList<NameValuePair>();
nvps.add(new BasicNameValuePair("auth", "login"));
nvps.add(new BasicNameValuePair("login", login));
nvps.add(new BasicNameValuePair("password", password));
nvps.add(new BasicNameValuePair("set_cookie", "on"));
httpost.setEntity(new UrlEncodedFormEntity(nvps));
HttpResponse response = httpclient.execute(httpost);
HttpEntity entity = response.getEntity();
302 FOUND is the common way of doing a "redirection", it seems Android or MacJVM is not performing that redirection. Are you using the same SDK version?
Try to use :
final HttpParams params = new BasicHttpParams();
HttpClientParams.setRedirecting(params, false);

Google authentication with Java apache http tokens

I'm trying to authenticate with Google using a simple Java program. I post to the correct URL with my credentials. I get a response with HTTP status code 200 but that doesn't contain any of the authentication tokens that I need to retrieve feeds for the user. Here's the code
private static String postData = "https://www.google.com/accounts/ClientLogin?Content-type=application/x-www-form-urlencoded&accountType=GOOGLE&Email=xxxxxxxx&Passwd=xxxxx";
public GoogleConnector(){
HttpClient client=new DefaultHttpClient();
HttpPost method=new HttpPost(postData);
try{
HttpResponse response=client.execute(method);
System.out.println(response.toString());
}
catch(Exception e){
}
Ok, the first problem you have is that 'Content-Type' needs to be a header, not a request parameter. And secondly, POST parameters should be appended to the request body, not to the request URL. Your code should look something like this:
HttpClient client = new DefaultHttpClient();
HttpPost method = new HttpPost("https://www.google.com/accounts/ClientLogin");
method.setHeader("Content-Type", "application/x-www-form-urlencoded");
List<BasicNameValuePair> postParams = new ArrayList<BasicNameValuePair>(4);
postParams.add(new BasicNameValuePair("accountType", "GOOGLE"));
postParams.add(new BasicNameValuePair("Email", "xxxxxxx"));
postParams.add(new BasicNameValuePair("Passwd", "xxxxxx"));
postParams.add(new BasicNameValuePair("service", "cl"));
UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(postParams);
method.setEntity(formEntity);
HttpResponse response=client.execute(method);
System.out.println(response.toString());

Android https form submission?

Hi I'm having a lot of trouble submitting a simple form, I have searched around and it appears quite a few people have had the same problem but I haven't found an answer.
Here's my code so far:
public void postData(TextView txtResult, String user, String pass) throws ClientProtocolException, IOException {
HttpPost post = new HttpPost("https://www.mymeteor.ie");
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("username", user));
nameValuePairs.add(new BasicNameValuePair("userpass", pass));
post.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpClient client = new DefaultHttpClient();
HttpResponse response = client.execute(post);
HttpEntity entity = response.getEntity();
String responseText = EntityUtils.toString(entity);
txtResult.setText(responseText);
}
The above code will simply return the original page,
can anybody help me?
thanks
Are you sure that URL supports logging in via post that way? It looks to me like the login form sends the post data to this URL: https://www.mymeteor.ie/go/mymeteor-login-manager
I would also suspect you should be using some sort of API instead of just posting data to their login form, remotely.

Categories