1

我正在尝试使用 POST 方法从我的 JME 应用程序中访问 .svc 服务。但收到“错误要求”。以下是我的代码。

HttpConnection hc = (HttpConnection) Connector.open(url, Connector.READ_WRITE);
hc.setRequestMethod(HttpConnection.POST);
hc.setRequestProperty("User-Agent", "Profile/MIDP-1.0 Configuration/CLDC-1.0" );
hc.setRequestProperty("Content-Type", "text/xml; charset=utf-8");
hc.setRequestProperty("Content-Length", ""+(postMsg.getBytes().length));

out = hc.openOutputStream();
out.write(postMsg.getBytes());

System.out.println("hc.getResponseCode() = "+hc.getResponseCode()+ "  hc.getResponseMessage() = "+hc.getResponseMessage());

请告诉我代码有什么问题。

4

1 回答 1

0

我使用 Ksoap2-j2me-core jar 而不是 http,并使用我发现的以下代码 -

    SoapObject request = new SoapObject("namespace", "login");   

    request.addProperty("username", "pranav");   
    request.addProperty("password", "gangan");   


    //create the SOAP envelope   
    final SoapSerializationEnvelope env = new SoapSerializationEnvelope(SoapEnvelope.VER11);   
    env.setOutputSoapObject(request);   

    //create the transport and then call   
    final HttpTransport httpTransport = new HttpTransport("http://URL");   
    httpTransport.call("\"login\"", env);   

    SoapObject body = (SoapObject) env.bodyIn;   

    //body.getProperty(0) will return the content of the first tag inside body   
    Object response = body.getProperty(0);   
            System.out.println(response.toString);  
于 2012-08-08T10:15:32.960 回答