2

I've a service to consume, the details of the service are as follows.

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":"[email protected]","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]}}}

The javascript code to initiate from:

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

In your answer, you don't have to use all variables, I just need some help to get me going...

Edit: Please specify the next steps of how to send json data to the server after I set the request headers in xmlhttp. I'm not sure what URL to send data to the above service.

On the side can someone tell me how to test the above service in chrome postman?

2
  • What is your question exactly? I don't see a question.
    – vrijdenker
    Sep 25, 2014 at 14:55
  • edited to made it clear, what's the next step, how to encode json data for the server, Sep 25, 2014 at 14:57

1 Answer 1

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

Basically, you need to construct a string of your JSON, and call xmlhttp.send(jsonStr).

One way to create that JSON string is like this:

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

Also, you seem to be using the wrong address. Complete sample:

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);
8
  • Thanks Alxandar, also I'm not sure where to send data to? can you please figure it out from the headers I sent you? Is it going to be dev.domain.us/api/V02/JsonWs.svc/json/V02 or what? Basically what's the end point? Sep 25, 2014 at 15:04
  • and what is this cooking thing? Cookie: LogicAuth=3821F201156EA833......; path=/; HttpOnly Sep 25, 2014 at 15:05
  • Cookie header is just as it sounds, cookies. Although, I don't think you can set them in an XHR, you can always try.
    – Alxandr
    Sep 25, 2014 at 15:08
  • thanks I'm seeing the edits, any help with the chrome extension? I selected a post request, with body as Raw and selected JSON from the type next to it but getting some error forms, I posted the json string as it is in the body Sep 25, 2014 at 15:09
  • I have no idea how to do chrome extensions.
    – Alxandr
    Sep 25, 2014 at 15:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.