0

first I'm trying to be able to send a HttpResponse with parameters such as:

http://www.syslang.com/frengly/controller?action=translateREST&src=en&dest=iw&text=good&email=YYY&password=XXX

the code looks something like this:

DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost("http://www.syslang.com/frengly/controller");   
List<NameValuePair> pairs = new ArrayList<NameValuePair>();  
pairs.add(new BasicNameValuePair("src", "en")); 
pairs.add(new BasicNameValuePair("dest", "iw"));  
pairs.add(new BasicNameValuePair("text", "good"));                  
pairs.add(new BasicNameValuePair("email", "YYY")); 
pairs.add(new BasicNameValuePair("password", "XXX"));
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(pairs,HTTP.UTF_8);  
httpPost.setEntity(entity);  
HttpResponse response = httpClient.execute(httpPost); 
HttpEntity httpEntity = response.getEntity();

the API structure is available at http://www.frengly.com/ (under the API tab) and has a total of 5 parameters (src, dest, text, email, password).

so far every time I tried to call

HttpResponse response = httpClient.execute(httpPost); I keep getting an IO Exception :(

After that I should get something like this structure:

-<root>
  <text>good</text>
  <translation>טוב</translation>
  <translationFramed>טוב|</translationFramed>
  <missing/>
  <existing>good,</existing>
  <stat>1/1</stat>
</root>

I think I'll handle this part to build XML and parse it as I need

p.s: I checked Android, send and receive XML via HTTP POST method and many other links, which didn't help me a lot.

let me know if any code lines from my application needed...

Thanks in advance.

1 Answer 1

2

You don't need to POST. You need to GET instead.

// Construct your request here.
String requestURL= "http://www.syslang.com/frengly/controller?action=translateREST&src=en&dest=iw&text=good&email=YYY&password=XXX"

DefaultHttpClient httpClient = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(requestURL);
HttpResponse response = httpClient.execute(httpGet);

And also internet permission in your AndroidManifest.xml

<uses-permission android:name="android.permission.INTERNET"/>
<application
....
....
Sign up to request clarification or add additional context in comments.

4 Comments

thanks for your quick response, but this still isn't working. the same IO Exception is raised on the line "HttpResponse response = httpClient.execute(httpGet);" line :(
Did you add the Internet permission?
oh maybe I didn't :( , any chance you guide me through this, I am pretty noob in android dev
thanks a lot mate, how simply how useful I sure you saved me a lot of trouble... thanks again :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.