aspose file tools*
The moose likes Android and the fly likes Post the data to Server Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Mobile » Android
Bookmark "Post the data to Server" Watch "Post the data to Server" New topic
Author

Post the data to Server

vina parmar
Greenhorn

Joined: Nov 09, 2009
Posts: 22
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

Joined: Jan 08, 2009
Posts: 1400
    
    6

In android you can use NameValuePair to send data through post request



Swastik
vina parmar
Greenhorn

Joined: Nov 09, 2009
Posts: 22
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

Joined: Oct 12, 2008
Posts: 1369

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.


[List of FAQs] | [Android FAQ] | [Samuh Varta]
vina parmar
Greenhorn

Joined: Nov 09, 2009
Posts: 22
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

Joined: Oct 12, 2008
Posts: 1369

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

Joined: Nov 09, 2009
Posts: 22
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

Joined: Oct 12, 2008
Posts: 1369

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

Joined: Nov 09, 2009
Posts: 22
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

Joined: Nov 14, 2011
Posts: 1
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Post the data to Server
 
Similar Threads
toString
JTable, rowVector, addNotify()
Searching row in database by a column which is not a primary key
code for writing full-name
How to connect to the internet behind proxy ?