Tag: get

如何通过GET / POST发送安全密码?

我想用Java发送HTTPS请求并在GET或POST数据中发送密码。 它安全吗? 我可以将密码作为纯文本放在POST / GET字段中,当我使用https时,它会被保护吗? 或者我应该做更多的事情?

使用Java套接字获取GET请求

我正在编写一个简单的程序来向特定url“ http://badunetworks.com/about/ ”发送获取请求。 如果我将其发送到“ http://badunetworks.com ”,请求仍然有效,但我需要将其发送到about页面。 package badunetworks; import java.io.*; import java.net.*; public class GetRequest { public static void main(String[] args) throws Exception { GetRequest getReq = new GetRequest(); //Runs SendReq passing in the url and port from the command line getReq.SendReq(“www.badunetworks.com/about/”, 80); } public void SendReq(String url, int port) throws Exception { //Instantiate a […]

如何使用Http客户端在java中传递查询参数

我使用给定的代码在java中使用GET REST调用,但我收到错误代码:404即找不到。 但是当我在浏览器中使用相同的URL时,我得到了输出,它工作正常。我是JAVA的新手。 可能是我错误地传递了查询参数,但我没有得到它。 我在NETBEANS 7.1.2工作。 请帮忙。 import java.io.IOException; import java.io.OutputStreamWriter; import java.net.HttpURLConnection; import java.net.URL; public class Test { private static String ENDPOINT =”http://wisekar.iitd.ernet.in/active/api_resources.php/method/mynode?”; public static void main(String[] args) throws IOException { URL url = new URL(ENDPOINT + “key=” + “mykey” ); HttpURLConnection httpCon = (HttpURLConnection) url.openConnection(); httpCon.setDoOutput(true); httpCon.setRequestMethod(“GET”); OutputStreamWriter out = new OutputStreamWriter( httpCon.getOutputStream()); […]

REST如何在URI中传递包含“/”的值作为路径参数?

我正在使用Java中的HttpClient开发一个客户端来访问REST应用程序。 在这里我想传递两个参数name(value =“Kiran”)和地址(Value =“5th Corner / Road”)作为路径参数。 Sample url:-http://localhost:port/rest/name/Kiran/address/5th Corner/Road 但由于地址包含“/”作为值,因此它不会取实际值。 有没有办法在从Java访问REST应用程序时处理“/”。 任何帮助表示赞赏。

从JSP调用REST GET服务

我有一个动态设置应用程序页面标题的JSP。 但是,我希望能够根据系统用户调用获取用户详细信息的REST服务。 我已经拥有系统用户值,但需要调用后端服务以从数据库中获取详细信息。 这已经实现但我不知道如何设置JSP来执行此操作。 我不想使用javascript,因为这被用于extjs方面。

如何使用Java HttpServer / HttpExchange在GET中获取查询字符串?

我试图在Java中创建一个简单的HttpServer来处理GET请求,但是当我尝试获取请求的GET参数时,我注意到HttpExchange类没有方法。 有人知道一种简单的方法来读取GET参数(查询字符串)吗? 这是我的处理程序的样子: public class TestHandler{ @Override public void handle(HttpExchange exc) throws IOxception { String response = “This is the reponse”; exc.sendResponseHeaders(200, response.length()); // need GET params here OutputStream os = exc.getResponseBody(); os.write(response.getBytes()); os.close(); } } ..和主要方法: public static void main(String[] args) throws Exception{ // create server on port 8000 InetSocketAddress address = new InetSocketAddress(8000); […]

使用Java提交HTML表单数据以从jsp应用程序检索下载

我有一个不起眼的问题。 我正在将一些Perl移植到Java,并将Perl代码中的一个方法发布到jsp应用程序并下载一个zip文件。 Perl代码的工作部分如下所示,它似乎使用get来检索文件。 $mech->get ( $url ); $mech->submit_form( fields => { upload => variable1, selectValue => variable2, }, ); jsp页面如下: Extract Features File: Code: 13 14 15 我用来尝试访问它的Java代码: URL url = new URL(s.getUrlScheme(), s.getUrlHost(), s.getUrlFile()); String urlParameters = “upload=C:\\testFile.txt&selectValue=14”; HttpURLConnection connection = (HttpURLConnection)url.openConnection(); connection.setDoInput(true); connection.setDoOutput(true); connection.setInstanceFollowRedirects(false); connection.setRequestMethod(“POST”); connection.setRequestProperty(“Content-Type”, “text/html”); connection.setRequestProperty(“charset”, “ISO-8859-1”); connection.setRequestProperty(“Content-Length”, Integer.toString(urlParameters.length())); connection.setUseCaches(false); DataOutputStream […]

如何从java执行https GET请求

我写了一个java客户端,它执行http GET请求没有任何问题。 现在我想按顺序修改这个客户端 import org.apache.http.HttpHost; import org.apache.http.auth.AuthScope; import org.apache.http.auth.UsernamePasswordCredentials; import org.apache.http.client.CredentialsProvider; import org.apache.http.client.config.RequestConfig; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.BasicCredentialsProvider; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; private String executeGet(final String url, String proxy, int port) throws IOException, RequestUnsuccesfulException, InvalidParameterException { CloseableHttpClient httpclient = null; String ret = “”; RequestConfig config; try { String hostname = extractHostname(url); logger.info(“Hostname {}”, […]

http获取身体请求

我知道你不应该发送带有正文的HTTP GET请求,但是ceilometer web api迫使我这样做。 我正在开发一个ceilometer scala客户端,所以我需要一个scala / java方法来生成一个获取请求。 到目前为止,我尝试使用beeClient( http://www.bigbeeconsultants.co.uk )和使用httpConnection的普通Java但我收到404错误。 在curl中,我可以通过这种方式实现结果: curl -X GET -H “X-Auth-Token: ..long long token here..” -H “Content-Type: application/json” -d ‘{“q”: [{“field”: “resource”, “op”: “eq”, “value”: “gdfsf”}]}’ http://137.204.57.150:8777/v2/meters/ 这是我使用java HttpURLConnection的scala代码: import java.io._ import java.net._ val token = “myToken” val url = new URL(“http://137.204.57.150:8777/v2/meters/”) val body = “{\”q\”: [{\”field\”: \”resource\”, \”op\”: […]