Showing posts with label json to http header. Show all posts
Showing posts with label json to http header. Show all posts

Saturday, 16 March 2019

Convert JSONObject to http header


HTTP.toString’ method is used to convert json object to http header.

Example
JSONObject jsonObject = new JSONObject();

jsonObject.put("Request-URI", "https://self-learning-java-tutorial.blogspot.com/2014/09/servlets.html");
jsonObject.put("Method", "GET");
jsonObject.put("HTTP-Version", "HTTP/1.1");

String header = HTTP.toString(jsonObject);

App.java

package com.sample;

import org.json.HTTP;
import org.json.JSONObject;

public class App {

 public static void main(String args[]) {
  JSONObject jsonObject = new JSONObject();

  jsonObject.put("Request-URI", "https://self-learning-java-tutorial.blogspot.com/2014/09/servlets.html");
  jsonObject.put("Method", "GET");
  jsonObject.put("HTTP-Version", "HTTP/1.1");

  String header = HTTP.toString(jsonObject);

  System.out.println(header);

 }
}

Output

GET "https://self-learning-java-tutorial.blogspot.com/2014/09/servlets.html" HTTP/1.1




Previous                                                 Next                                                 Home