Jersey Client JSON

form data to Login using Java API "Client-side coding should be in Java " with Body (user,pass)this is send as JSON to Server.Server sends back log-in Message in JSON format

JSON Data send by Client Looks like this

{
“usr”:"@gmail.com",
“pwd”:“mat”
}
I Need Client side Code in Java which might Look like this(some what).Please help.

public class NetClientPost {

public static void main(String[] args) {

	try {

		URL url = new URL(
				"https://mat.erpnext.com/api/method/login");
		Httpconn = (Http) url.Connection();
		conn.setDoOutput(true);
		conn.setRequestMethod("POST");
		conn.set("Content-Type", "application/json");

		String input = "{\"usr\": \"mat@gmail.com\", \"pwd\": \"mat\"}";
		
		os.write(input.getBytes());
		os.flush();

	if (conn.getResCo() != Http. {
			throw new RuntimeException("Failed : HTTP error code : "
					+ conn.getResponseCode());
		}

		BufferedReader br = new BufferedReader(new InputStreamReader(
				(conn.getInputStream())));

		String output;
		System.out.println("Output from Server .... \n");
		while ((output = br.readLine()) != null) {

			System.out.println(output);
		}

		conn.disconnect();

	} catch (MalformedException e) {

		e.printStackTrace();
	} catch (IOException e) {

		e.printStackTrace();

	}

}

}

I am getting Error 401 . Why ?

Hi,
Guess it should be HttpsURLConnection when connecting secure URL.
Thanks

Try if ScribeJava library is useful, it supports frappe server,
here’s frappe example

also try removing all spaces from stringified json,

change

String input = "{\"usr\": \"mat@gmail.com\", \"pwd\": \"mat\"}";

to

String input = "{\"usr\":\"mat@gmail.com\",\"pwd\":\"mat\"}";

this didnt help