Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Post the data to Server

 
vina parmar
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

How can I post data to Server.
I have Checked it with get Method. Now i have to use through POST method how can I pass it.

String url = "http://myname.cmpname.com/mobile/search.php?name=mobile&surname=developer";

eg.

String url = "http://myname.cmpname.com/mobile/search.php?name=mobile&surname=developer";
which I have tried using HttpGet
How can I post data name=mobile, surname=developer , Address=Palo Alto , CA, USA likewise?

Thanks



 
Swastik Dey
Rancher
Posts: 1604
5
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In android you can use NameValuePair to send data through post request

 
vina parmar
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Swastik,
It's working.

But my problem is response now coming in XML format. And I am using DOM parser.
I can able to parse it through
String url = "http://myname.cmpname.com/mobile/search.php?name=mobile&surname=developer";
URL url = new URL(link);
DocumentBuilder builder = factory.newDocumentBuilder();
Document dom = builder.parse(url.openConnection().getInputStream());

Now when I passing the response String in builder.parse(response) as you have given me
String response=hc.execute(postMethod,res);
it is giving error as
org.xml.sax.SAXParseException: InputSource needs either stream or reader
I am not using SAXParser at all.

My code is.


It will fetch the data getting response in the string but giving error at Document dom = builder.parse(response);

What am I missing or where am I wrong?
 
Monu Tripathi
Rancher
Posts: 1369
1
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It will fetch the data getting response in the string but giving error at Document dom = builder.parse(response);

What am I missing or where am I wrong?


I think, you need to read the API documentation before using it in your code.
For instance, had you read the documentation for builder.parse(response) method you would have known that it takes InputStream as a parameter and not String.
 
vina parmar
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes Monu that is why.
I am just trying for that because it is not giving me any compile time error.
I have pasted my code because anyone can understand my problem and can suggest because there is no method to get InputStream in HttpPost..

Thanks
 
Monu Tripathi
Rancher
Posts: 1369
1
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
vina parmar wrote:
I have pasted my code because anyone can understand my problem and can suggest because there is no method to get InputStream in HttpPost..
Thanks

I think otherwise; there IS a method to get your response as InputStream. But to get to that, as I have already said, you need to read the documentation first. Try this:


Alternatively, you could have also converted your response String into a stream...

Hope that helps.
 
vina parmar
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Monu.
It's working really fine.
And I am reading the Document, side by side I am just trying to implement, that is why question arises.

Thanks for your support.

One question : I have created 3 Activity. On the start up screen it shows me all the three activity with the icon, which I don't want.
While other application like ApiDemos don't have this kind of behavior, why is it so?
how can I resolve it?
 
Monu Tripathi
Rancher
Posts: 1369
1
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One question : I have created 3 Activity. On the start up screen it shows me all the three activity with the icon, which I don't want.
While other application like ApiDemos don't have this kind of behavior, why is it so?
how can I resolve it?


Do you understand everything that you've written in your manifest file?
For e.g: what does <category android:name="android.intent.category.LAUNCHER" /> in the <intent-filter> tag of your activity mean?
 
vina parmar
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Really Sorry for that.
I didn't.
Now I am reading whole document.

Thanks for your co-operation and suggestions.

Thanks a lot.
 
Franco Salomone
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Swastik Dey wrote:In android you can use NameValuePair to send data through post request



I have a problem with this code, I'm trying to send, via POST method, the info U=USUARI and K=PASSWORD to this URL: http://stats.serhstourism.com/?U=USUARI&K=PASSWORD
But I have a form in the android app that has two EditText's: Usuari_TXT and Clau_TXT, how can I link this two objects to the POST method sending?
I can send you the source code via PM if you need it.

thanks a lot!
F.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic