2

我有一个服务要消费,服务的细节如下。

POST /API/v02/JsonWs.svc/json/V02 HTTP/1.1 [OR] POST /API/Public/v02/JsonWs.svc/json/V02 HTTP/1.1
 Host: dev.domain.us
 Content-Type: application/json; charset=utf-8
Cookie: LogicAuth=3821F201156EA833......; path=/; HttpOnly

{"Header":{"Procedure":"Family_Insert"},"Body":{"EmailAddress":"email22222@domain.net","Password":"test14","IdPhoneNumber":3051234567,"Address":{"Line1":"1234 Avenue","Line2":"Suite 900","City":"Coral","ZipCode":"33327","State":{"IdState":10}},"TimeZone":{"IdTimeZone":-5},"User":{"IdGender":1,"NameFirst":"Tom","NameMiddle":"Larry","NameLast":"Lewis","DateBirth":"10-21-1978","ClubName":"ABC","Communities":[1,2],"UserConnectTypes":[3,4]}}}

要从以下位置启动的 javascript 代码:

var xmlhttp = new XMLHttpRequest(); 
xmlhttp.open("POST", "/json-handler");
xmlhttp.setRequestHeader("Content-Type", "application/json;charset=UTF-8");

在您的回答中,您不必使用所有变量,我只需要一些帮助才能让我继续前进......

编辑:请指定在我设置请求标头后如何将 json 数据发送到服务器的后续步骤xmlhttp。我不确定将数据发送到上述服务的 URL。

有人可以告诉我如何在 chrome postman 中测试上述服务吗?

4

1 回答 1

3
xmlhttp.send('{"Header":{"Procedure".......');

基本上,您需要构造一个 JSON 字符串,然后调用xmlhttp.send(jsonStr).

创建 JSON 字符串的一种方法如下:

var jsonStr = JSON.stringify({
  Header: {
    Procedure: 'Family_Insert'
  },
  Body: ....
});

另外,您似乎使用了错误的地址。完整样本:

var xhr = new XMLHttpRequest();
xhr.open('POST', 'http://dev.domain.us/API/v02/JsonWs.svc/json/V02');
xhr.setRequestHeader('Content-Type', 'application/json; charset=utf-8');
var jsonStr = JSON.stringify({
   Header: {
      Procedure: 'Family_Insert'
   },
   Body: ....
});
xhr.send(jsonStr);
于 2014-09-25T15:01:57.760 回答