简体   繁体   中英

Unirest-JAVA Wont Query

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:

My Errors in Image

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM