Soap api插入数据请求在Java中不起作用

Soap api插入数据请求在Java中不起作用,java,xml,api,soap,Java,Xml,Api,Soap,我必须为一个小项目使用SOAP api。我现在可以检索数据,但当我尝试插入数据时,它似乎不起作用,并导致以下错误:服务器无法处理请求。-->对象引用未设置为对象的实例。 我正在为post请求使用以下soap资源: 我有以下代码: OkHttpClient client = new OkHttpClient(); MediaType mediaType = MediaType.parse("text/xml"); RequestBody body = Requ

我必须为一个小项目使用SOAP api。我现在可以检索数据,但当我尝试插入数据时,它似乎不起作用,并导致以下错误:服务器无法处理请求。-->对象引用未设置为对象的实例。

我正在为post请求使用以下soap资源:

我有以下代码:

 OkHttpClient client = new OkHttpClient();
    MediaType mediaType = MediaType.parse("text/xml");
    RequestBody body = RequestBody.create(mediaType, "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n<soap12:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap12=\"http://www.w3.org/2003/05/soap-envelope\">\r\n  <soap12:Body>\r\n    <InsertData xmlns=\"http://202.61.51.93:6265/\">\r\n      <userName>string</userName>\r\n      <password>string</password>\r\n      <costCenterCode>string</costCenterCode>\r\n      <consigneeName>string</consigneeName>\r\n      <consigneeAddress>string</consigneeAddress>\r\n      <consigneeMobNo>string</consigneeMobNo>\r\n      <consigneeEmail>string</consigneeEmail>\r\n      <originCityName>string</originCityName>\r\n      <destinationCityName>string</destinationCityName>\r\n      <pieces>string</pieces>\r\n      <weight>string</weight>\r\n      <codAmount>0.2</codAmount>\r\n      <custRefNo>string</custRefNo>\r\n      <productDetails>string</productDetails>\r\n      <fragile>string</fragile>\r\n      <services>string</services>\r\n      <remarks>string</remarks>\r\n      <insuranceValue>string</insuranceValue>\r\n    </InsertData>\r\n  </soap12:Body>\r\n</soap12:Envelope>");
    Request request = new Request.Builder()
            .url("http://webapp.tcscourier.com/codapi/Service1.asmx?op=InsertData")
            .method("POST", body)
            .addHeader("Content-Type", "text/xml")
            .build();
    try {
        Response response = client.newCall(request).execute();

        JSONObject xmlJSONObj = XML.toJSONObject(response.body().string());
        System.out.println(xmlJSONObj.toString());
    } catch (IOException e) {
        e.printStackTrace();
    }
OkHttpClient=new-OkHttpClient();
MediaType MediaType=MediaType.parse(“text/xml”);
RequestBody=RequestBody.create(mediaType,“\r\n\r\n\r\n\r\n string\r\n string\r\n string\r\n string\r\n string\r\n string\r\n string\r\n string\r\n string\r\n 0.2\r\n string\r\n string\r\n string\r\n string\r\n string\r\n string\r\n string\r\n string\r\n string\r\n”;
Request Request=newrequest.Builder()
.url(“http://webapp.tcscourier.com/codapi/Service1.asmx?op=InsertData")
.方法(“后”,正文)
.addHeader(“内容类型”、“文本/xml”)
.build();
试一试{
Response=client.newCall(request.execute();
JSONObject xmlJSONObj=XML.toJSONObject(response.body().string());
System.out.println(xmlJSONObj.toString());
}捕获(IOE异常){
e、 printStackTrace();
}

我缺少什么?

请尝试在请求中添加SoapAction标头


addHeader(“soapaction”http://202.61.51.93:6265/InsertData")

一定有某种内部需求,我们在不知情的情况下无法知道。我曾在另一个web服务中尝试过,它确实有效。我建议任何想要了解SOAP的人先了解一下Postman,然后再转向Java。我的一个宝贵资源是以下链接: