Thursday, March 6, 2014

Help using android-xmlrpc lead connection to http://10.0.2.2:8080 refused


posts by huoyunfenlan on 2012-03-31 02:48:59 Edit
I made an android application in, you need to use xml rpc.
server-side via java client tested OK.
Android client side now, and every time I XMLRPCEXCEPTION
tipsorg.xmlrpc.android.XMLRPCException: org.apache.http.conn.HttpHostConnectException: Connection to http://10.0.2.2:8080 refused

Relevant code is as follows:

import org.xmlrpc.android.XMLRPCClient;
import org.xmlrpc.android.XMLRPCException;


public int msg = 0x0000;
public String showMsg = null;


try {
XMLRPCClient client = new XMLRPCClient ("http://10.0.2.2:8080/hynXmlRpcServer1/xmlrpc");
showMsg = (String) client.call ("sendCommand", msg);
} Catch (XMLRPCException e) {
showMsg = e.toString ();
}

canvas.drawText (showMsg, 50, 30, paint);



In addition, org.xmlrpc.android.XMLRPCClient me down under is a folder does not jar, so I direct the org entire folder to my project came up on (Test.java deleted), so it should be right ?


I was a novice, experts explain, very grateful!<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
10.0.2.2 What is the address ah? If you go is gprs, we need the public IP network
Reply:
android emulator server when connecting the machine, use localhost as the emulator will be the default server, you must use 10.0.2.2, otherwise there will be connection to http://localhost:8080 refused XmlRpcException
Reply:
Can not directly access this, you need to use port redirection
Reply:
Why can not directly access? I see a lot of android xml rpc examples are used 10.0.2.2:8080 visit, which includes examples Test.java android-xmlrpc This package also wrote http://10.0.2.2:8888.
Please let me know, thank you!
Reply:
Finally themselves, the solution is as follows:


Inside manifest.xml need to add network access permission.




Further, if there android.os.NetworkOnmainThreadException issue is related with the version.
Add the following code to solve Red:

public void onCreate (Bundle savedInstanceState) {

StrictMode.setThreadPolicy (new StrictMode.ThreadPolicy.Builder ()
. DetectDiskReads ()
. DetectDiskWrites ()
. DetectNetwork () / / or. DetectAll () for all detectable problems
. PenaltyLog ()
. Build ());
StrictMode.setVmPolicy (new StrictMode.VmPolicy.Builder ()
. DetectLeakedSqlLiteObjects ()
. DetectLeakedClosableObjects ()
. PenaltyLog ()
. PenaltyDeath ()
. Build ());


super.onCreate (savedInstanceState);
Reply:
I also encountered; up!
Reply:
Using the above method to solve the tangle for a long
Reply:
Thank, according to this method to get

No comments:

Post a Comment