problem in Http Connection to send data

Problems with WiFi, SQLite ,Bluetooth, WiMax, Proxies, etc...

problem in Http Connection to send data

Postby sri_reddy523 » Sun Apr 05, 2009 3:18 am

Hi I am trying to establish the connection between mobile and PC.I am running server program on PC, when I run the below code server not displaying any response message.When I send the request from mobile browser server displaying response message. I am working on SDK_1.1.Please suggest me on program code........................................

public class HTTPPostExample extends Activity {
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
try{
httpPostImage();
}
catch(Exception e)
{}
}
}
public void httpPostImage() throws Exception {

HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://157.182.195.189:6666/");

//File file = new File("/data/data/org.emrah/icon.png");
// InputStreamEntity reqEntity = new InputStreamEntity(new FileInputStream(file), -1);


reqEntity.setContentType("application/x-www-form-urlencoded");

Header[] headers = new BasicHeader[2];
headers[0] = new BasicHeader("Accept","application/xml");
headers[1] = new BasicHeader("Content-type", "application/x-www-form-urlencoded");
httppost.addHeader(headers[0]);
httppost.addHeader(headers[1]);

//httppost.setEntity(reqEntity);

System.out.println("executing request " + httppost.getRequestLine());
HttpResponse response = httpclient.execute(httppost);
HttpEntity resEntity = response.getEntity();
sri_reddy523
Freshman
Freshman
 
Posts: 3
Joined: Fri Mar 27, 2009 8:18 am

Top

Postby javame_android » Mon Apr 06, 2009 10:38 am

Hi,

Please make sure that the headers that you are passing are absolutely correct and accepted by the server. And are you passing the same url while testing it from the code and from the browser. I think there must be the issue of headers that are being passed. Since when you are calling the url from browser then browser would be passing headers appropriately but not with the code.

Hope that helps you.
Thanks & Regards
Sunil
javame_android
Junior Developer
Junior Developer
 
Posts: 19
Joined: Wed Mar 25, 2009 11:00 am
Location: Ahmedabad

Re: problem in Http Connection to send data

Postby noori » Tue Apr 21, 2009 5:46 am

Could you make it to work?

I am working on a project to send a file to our server. If your code works I want to use it.

can you add more comments and explain how each line works?
Thanks

sri_reddy523 wrote:Hi I am trying to establish the connection between mobile and PC.I am running server program on PC, when I run the below code server not displaying any response message.When I send the request from mobile browser server displaying response message. I am working on SDK_1.1.Please suggest me on program code........................................

public class HTTPPostExample extends Activity {
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
try{
httpPostImage();
}
catch(Exception e)
{}
}
}
public void httpPostImage() throws Exception {

HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://157.182.195.189:6666/");

//File file = new File("/data/data/org.emrah/icon.png");
// InputStreamEntity reqEntity = new InputStreamEntity(new FileInputStream(file), -1);


reqEntity.setContentType("application/x-www-form-urlencoded");

Header[] headers = new BasicHeader[2];
headers[0] = new BasicHeader("Accept","application/xml");
headers[1] = new BasicHeader("Content-type", "application/x-www-form-urlencoded");
httppost.addHeader(headers[0]);
httppost.addHeader(headers[1]);

//httppost.setEntity(reqEntity);

System.out.println("executing request " + httppost.getRequestLine());
HttpResponse response = httpclient.execute(httppost);
HttpEntity resEntity = response.getEntity();
noori
Freshman
Freshman
 
Posts: 6
Joined: Tue Apr 21, 2009 5:42 am

Top

Return to Networking & Database Problems

Who is online

Users browsing this forum: No registered users and 4 guests