I am having trouble getting Unirest to query a site via JSON.
Code:
AuthLIB.java:
import java.io.FileWriter;
import java.io.IOException;
import java.io.*;
import java.net.*;
import java.util.*;
import com.mashape.unirest.http.*;
import com.mashape.unirest.request.*;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
public class AuthLIB
{
public void authenticate(String input[]) throws Exception
{
System.out.println("Auth Request");
HttpResponse<JsonNode> jsonResponse = Unirest.post("https://mysafewebsite.com/cow")
.header("accept", "application/json")
.field("username", input[0])
.field("password", input[1])
.asJson();
System.out.println(jsonResponse);
}
public AuthLIB()
{
System.out.println("Auth Constructed");
}
}
I am getting errors:
This is very frustrating not to have the posting working.
Help Please
<3 Candy
As from the image you posted the problem seems to be that Java cannot find the Unirest class.
How do you include Unirest?
I recommend using Maven (this also gets all required dependencies of Unirest):
<dependency>
<groupId>com.mashape.unirest</groupId>
<artifactId>unirest-java</artifactId>
<version>1.4.9</version>
</dependency>