0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

NeustarでJSONをPOSTする

Posted at

ハマったので備忘。
APIにJSON渡して、戻ってきたJSONを受け取ってまたゴニョゴニョしたいときなどに。

var client = test.openHttpClient();
client.setFollowRedirects(false);

test.beginTransaction();
test.beginStep("Step-001");

// Request
var url = 'https://example.com/api/getName';
var request = client.newPost(url);
request.addRequestHeader("Content-Type", "application/x-www-form-urlencoded");

var json = {
   id:'hoge'
};
var strJson = JSON.stringify(json);
request.setRequestBody(strJson);

// Response
var response = request.execute();
var code = response.getStatusCode();
test.log(code);
var body = response.getBody();
test.log(body);

var obj = JSON.parse(body)
test.log(obj.name);

test.endStep();
test.endTransaction();
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?