我使用Jira RestApi和Java编码,我无法完成任务。任何人都可以帮我解决这个问题吗?我无法在这里打电话给其余的api
import static java.nio.charset.StandardCharsets.*;
package jira.rest.api;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.URI;
import java.nio.charset.Charset;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import com.sun.jna.platform.win32.COM.TypeLibUtil.IsName;
public class JiraManager {
private final String m_BaseUrl = "http://localhost.:8080/rest/api/latest/";
private String m_Username;
private String m_Password;
public JiraManager(String username, String password) {
m_Username = username;
m_Password = password;
}
@SuppressWarnings("deprecation")
public void RunQuery() throws ClientProtocolException,
IOException {
String data = null;
String argument = null;
String method = "GET";
String url = String.format("{0}{1}/", m_BaseUrl, "project");
if (argument != null) {
url = String.format("{0}{1}/", url, argument);
}
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost(m_BaseUrl);
HttpResponse response = client.execute(post);
BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
String line = "";
while ((line = rd.readLine()) != null) {
System.out.println(line);
}
}
private String GetEncodedCredentials() {
String mergedCredentials = String.format("{0}:{1}", m_Username,
m_Password);
byte[] byteCredentials = mergedCredentials.getBytes(Charset
.forName("UTF-8"));
String val = "";
try {
val = new String(byteCredentials, "UTF-8");
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return val;
}
}
我的主类使用以下代码调用其余的api:
package jira.rest.api;
import java.io.IOException;
import org.apache.http.client.ClientProtocolException;
public class main {
public main() {
// TODO Auto-generated constructor stub
}
public static void main(String[] args) throws ClientProtocolException,
IOException {
// TODO Auto-generated method stub
String username = "sbodhuluri";
String password = "Quad@2014";
JiraManager manager = new JiraManager(username, password);
manager.RunQuery();
System.out.println("Hello and welcome to a Jira Example application!");
}
}