0

我正在使用来自http://jsonrpcphp.org/?page=example&lang=en的 JSON-RPC PHP 创建 php jsonrpc 作为服务器

和 android-json-rpc 作为 android http://code.google.com/p/android-json-rpc/的客户端

我的服务器没问题,我可以从 php 调用它,但是当我从 android 调用它时,它给了我系统错误,我无法解决它,任何人都可以帮忙吗?

07-10 23:36:01.685: W/System.err(457): org.alexd.jsonrpc.JSONRPCException: IO error
07-10 23:36:01.685: W/System.err(457):  at org.alexd.jsonrpc.JSONRPCHttpClient.doJSONRequest(JSONRPCHttpClient.java:142)
07-10 23:36:01.695: W/System.err(457):  at org.alexd.jsonrpc.JSONRPCClient.doRequest(JSONRPCClient.java:77)
07-10 23:36:01.695: W/System.err(457):  at org.alexd.jsonrpc.JSONRPCClient.callJSONArray(JSONRPCClient.java:528)
07-10 23:36:01.695: W/System.err(457):  at com.afaqy.afaqytemp.AfaqyTempActivity.login(AfaqyTempActivity.java:63)
07-10 23:36:01.695: W/System.err(457):  at com.afaqy.afaqytemp.AfaqyTempActivity.access$0(AfaqyTempActivity.java:41)
07-10 23:36:01.695: W/System.err(457):  at com.afaqy.afaqytemp.AfaqyTempActivity$1.onClick(AfaqyTempActivity.java:34)
07-10 23:36:01.695: W/System.err(457):  at android.view.View.performClick(View.java:2408)
07-10 23:36:01.695: W/System.err(457):  at android.view.View$PerformClick.run(View.java:8816)
07-10 23:36:01.695: W/System.err(457):  at android.os.Handler.handleCallback(Handler.java:587)
07-10 23:36:01.695: W/System.err(457):  at android.os.Handler.dispatchMessage(Handler.java:92)
07-10 23:36:01.705: W/System.err(457):  at android.os.Looper.loop(Looper.java:123)
07-10 23:36:01.705: W/System.err(457):  at android.app.ActivityThread.main(ActivityThread.java:4627)
07-10 23:36:01.705: W/System.err(457):  at java.lang.reflect.Method.invokeNative(Native Method)
07-10 23:36:01.705: W/System.err(457):  at java.lang.reflect.Method.invoke(Method.java:521)
07-10 23:36:01.705: W/System.err(457):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
07-10 23:36:01.705: W/System.err(457):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
07-10 23:36:01.705: W/System.err(457):  at dalvik.system.NativeStart.main(Native Method)
07-10 23:36:01.705: W/System.err(457): Caused by: java.net.SocketException: Permission denied
07-10 23:36:01.715: W/System.err(457):  at org.apache.harmony.luni.platform.OSNetworkSystem.createStreamSocketImpl(Native Method)
07-10 23:36:01.715: W/System.err(457):  at org.apache.harmony.luni.platform.OSNetworkSystem.createStreamSocket(OSNetworkSystem.java:186)
07-10 23:36:01.715: W/System.err(457):  at org.apache.harmony.luni.net.PlainSocketImpl.create(PlainSocketImpl.java:265)
07-10 23:36:01.715: W/System.err(457):  at java.net.Socket.checkClosedAndCreate(Socket.java:873)
07-10 23:36:01.715: W/System.err(457):  at java.net.Socket.connect(Socket.java:1020)
07-10 23:36:01.715: W/System.err(457):  at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:119)
07-10 23:36:01.715: W/System.err(457):  at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:143)
07-10 23:36:01.715: W/System.err(457):  at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
07-10 23:36:01.715: W/System.err(457):  at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
07-10 23:36:01.715: W/System.err(457):  at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:348)
07-10 23:36:01.715: W/System.err(457):  at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
07-10 23:36:01.715: W/System.err(457):  at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
07-10 23:36:01.725: W/System.err(457):  at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
07-10 23:36:01.725: W/System.err(457):  at org.alexd.jsonrpc.JSONRPCHttpClient.doJSONRequest(JSONRPCHttpClient.java:110)
07-10 23:36:01.725: W/System.err(457):  ... 16 more

我的安卓代码是

        JSONRPCClient clientrpc = JSONRPCClient.create("http://192.168.1.102/server.php",JSONRPCParams.Versions.VERSION_2);
      clientrpc.setConnectionTimeout(2000);

      clientrpc.setSoTimeout(2000);
        try 
        {
          JSONArray stringdata = clientrpc.callJSONArray("login","demo","123456");

          try {
            Toast.makeText(getApplicationContext(),
                        stringdata.getString(1), Toast.LENGTH_SHORT)
                        .show();
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            //  e.printStackTrace();
            Toast.makeText(getApplicationContext(),
                    "ERROR ON CHECKLOGIN", Toast.LENGTH_SHORT)
                    .show();
        }

        }
        catch (JSONRPCException e)
        {
          e.printStackTrace();
            Toast.makeText(getApplicationContext(),
                    "Error ON server connection", Toast.LENGTH_SHORT)
                    .show();
        }

json输出的数组

    [Logedin] => 1
    [drivers] => Array
        (

}   
    [objects] => Array
        (

}   
4

1 回答 1

1

谢谢,放了之后就可以了

<uses-permission android:name="android.permission.INTERNET" />

AndroidManifest.xml由于套接字权限而发生此错误。

于 2012-08-11T18:47:57.453 回答