Reputation: 11
I am new to android and I'm making a simple app that sends a JSON object to the server. The many examples that I found on the internet had the following three lines of code:
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(prepai.host22.com/LoadStory.php);
HttpResponse httpResponse = httpClient.execute(httpPost);
I tried to run them but the app running in the eclipse emulator crashed when the execute() function got executed. I got this log:
Caused by: java.lang.IllegalStateException: Target host must not be null, or set in parameters. scheme=null, host=null, path=prepai.host22.com/LoadStory.php
How do I give the host a value? Also do I have to do all the communication in a separate thread? Or is there anything else that I need to do?
Upvotes: 1
Views: 124
Reputation: 518
You should pass the full url (including the http or https) as a string, for example:
HttpPost httpPost = new HttpPost("http://prepai.host22.com/LoadStory.php");
Upvotes: 1