Java tutorial
//package com.java2s; //License from project: Open Source License import android.util.Log; import java.io.IOException; import java.io.OutputStream; import java.io.PrintWriter; import java.util.Date; public class Main { public static void responseJSONError(OutputStream output, String responseText) { response(output, "application/json", "400 OK", responseText); } public static void response(OutputStream output, String contentType, String description, String responseText) { Log.d(">>>NativeH5", " xhr response return start time:" + System.currentTimeMillis() + " responseText:" + responseText); PrintWriter pw = new PrintWriter(output); pw.println("HTTP/1.1 " + description); pw.println("Content-Type: " + contentType); pw.println("Date: " + new Date()); pw.println("Access-Control-Allow-Origin: *"); pw.println("Content-Length: " + responseText.length()); pw.println(); pw.println(responseText); pw.flush(); try { output.close(); } catch (IOException e) { e.printStackTrace(); } } }