1

I am trying to hit .svc service from my JME application using POST method. but getting 'bad request'. Following is my code.

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());

Please tell me what is wrong with the code.

4

1 に答える 1

0

httpの代わりに、私が見つけた次のコードでKsoap2-j2me-core jarを使用しました-

    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 に答える