Tag: http post

HttpPost – >重定向 – >所需响应的位置或主体

以下是将数据POST到网站而不是作为响应重定向的Java代码(状态302)。 它在我的PC(Eclipse,Java,Ubuntu)上完美运行,它完全符合我的要求。 我尝试了很多东西来发布代码function,但我无法做到。 Java代码: // Preparing the CLIENT and POST Method HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost(“http://na.leagueoflegends.com/ladders/solo-5×5”); try { // Add your POST METHOD attributes List nameValuePairs = new ArrayList(2); nameValuePairs.add(new BasicNameValuePair(“op”, “Search”)); nameValuePairs.add(new BasicNameValuePair(“player”, “Jaiybe”)); nameValuePairs.add(new BasicNameValuePair(“ladder_id”, “3”)); nameValuePairs.add(new BasicNameValuePair(“form_build_id”, “form-526370b788622996caa3669e7b975ccf”)); nameValuePairs.add(new BasicNameValuePair(“form_id”, “ladders_filter_form”)); httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); // Execute HTTP Post […]

HttpURLConnection即使在setDoOutput(true)之后执行get请求,setRequestMethod(“POST”)setRequestProperty(“Content”

这是代码: String Surl = “http://mysite.com/somefile”; String charset = “UTF-8”; query = String.format(“param1=%s&param2=%s”, URLEncoder.encode(“param1”, charset), URLEncoder.encode(“param2”, charset)); HttpURLConnection urlConnection = (HttpURLConnection) new URL(Surl + “?” + query).openConnection(); urlConnection.setRequestMethod(“POST”); urlConnection.setDoOutput(true); urlConnection.setUseCaches(false); urlConnection.setAllowUserInteraction(false); urlConnection.setRequestProperty(“Accept-Charset”, charset); urlConnection.setRequestProperty(“User-Agent”,”Android”); urlConnection.setRequestProperty(“Content-Type”,”application/x-www-form-urlencoded;charset=” + charset); urlConnection.connect(); 以上仍然是GET请求。 我在服务器上使用PHP,并且能够通过$_GET变量而不是$_POST变量访问查询的’name = value’参数 测试2.3.7(设备)。 我错过了什么?

从Java中的HTTP POST请求中读取JSON消息

我是Java和客户端 – 服务器编程的新手。 我正在使用嵌入式Jetty,我正在尝试将JSON字符串发送到某个地址( http:// localhost:7070 / json ),然后在该地址中显示JSON字符串。 我尝试了以下代码,但我得到的只是null。 嵌入式Jetty代码: public static void main(String[] args) throws Exception { Server server = new Server(7070); ServletContextHandler handler = new ServletContextHandler(server, “/json”); handler.addServlet(ExampleServlet.class, “/”); server.start(); } 用于发送Http POST的客户端function: public static void sendHttp(){ HttpClient httpClient = HttpClientBuilder.create().build(); //Use this instead try { HttpPost request = new HttpPost(“http://localhost:7070/json”); JSONObject […]

在Android中使用MultipartEntityBuilder时,HttpPost返回错误

我正在尝试查询“ http://www.idmypill.com/api/id/”api ,我收到的JSON字符串是{“results”:[],”success”:false,”errors”:null}这是我的服务处理程序类: public String makeServiceCall(String url, int method, String api, byte[] pillImage) { try { // http client DefaultHttpClient httpClient = new DefaultHttpClient(); HttpEntity httpEntity = null; HttpResponse httpResponse = null; // Checking http request method type if (method == POST) { android.os.Debug.waitForDebugger(); HttpPost httpPost = new HttpPost(url); httpPost.setHeader(“data = api_key”, api); MultipartEntityBuilder builder […]

如何从URL中提取参数,无论其编写方式如何?

我想要一种java方法来提取URL的参数,无论这些参数是如何写入其中的,都是常规方式,如( https://www.facebook.com/Doly.mohamed.Smile9?ref=stream&hc_location=stream )这很简单,因为我所要做的就是: URL url = new URL(“www.blabla….etc”); String query = url.getQuery(); try{ String [] params = query.split(“&”); for(int i= 0 ; i < params.length; i++){ String [] split = params[i].split("="); parameters.put(split[0], split[1]); } }catch(NullPointerException ex){} 所以参数值是: key = ref value = stream , key = hc_location value = stream 但是,如果URL具有以其他方式编写的参数,或者如果URL没有像doPost()方式那样在其中写入参数,我该怎么办? 有没有办法从URL获取extraPathInfo而不使用servlet?

使用Java发送HTTP请求GET / POST以形成?

所以我有这段代码,我得到它的工作,现在它基本上允许我发送httppost并获取几乎任何我想要的外部网站的请求除非元素不包含name属性。 这是一个例子: 这是Java代码: public static String sendPostRequest(String url) { StringBuffer sb = null; try { String data = URLEncoder.encode(“user”, “UTF-8”) + “=” + URLEncoder.encode(“myUserName”, “UTF-8”) + “&” + URLEncoder.encode(“submit”, “UTF-8”) + “=” + URLEncoder.encode(“Submit”, “UTF-8”); URL requestUrl = new URL(url); HttpURLConnection conn = (HttpURLConnection) requestUrl .openConnection(); conn.setDoOutput(true); conn.setRequestMethod(“GET”); OutputStreamWriter osw = new OutputStreamWriter( conn.getOutputStream()); osw.write(data); […]

如何在Java Android中为客户端请求设置HttpPost标头

我无法让Apache HttpClient正确发送HttpPost标头。 我没有问题发送名称值对等等,但每当我设置或添加POST标头时,它会在发出请求时消失。 我已经尝试了setHeader和addHeader,以及同时尝试这两个。 这是我的代码: HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost(“https://posttestserver.com/post.php”); httppost.setHeader(“Authorization: Bearer”, accessToken); httppost.addHeader(“Authorization: Bearer”, accessToken); Log.d(“DEBUG”, “HEADERS: ” + httppost.getFirstHeader(“Authorization: Bearer”)); ResponseHandler responseHandler = new BasicResponseHandler(); String responseBody = httpclient.execute(httppost, responseHandler); Log.d(“DEBUG”, “RESPONSE: ” + responseBody); 此外,执行请求之前的调试语句打印出正确的标题,因此我知道它正在添加,然后稍后删除。 任何帮助将非常感激! 编辑:如果重要的话,这都在AsyncTask中运行。 我认为没有,因为有一个NetworkOnMainThreadexception抛出,但我认为值得一提。

JAVA:http发布请求

我必须向web服务发送请求,以使用用户名和密码对用户进行身份validation。 我对以下post请求有疑问: public String postTest(String action, ConnectionParametrData [] parameters) { Uri.Builder builder = new Uri.Builder().scheme(scheme).authority(authority).path(action); uri = builder.build(); BufferedReader in = null; String ans = null; HttpPost request = new HttpPost(uri.toString()); HttpClient defaultClient = new DefaultHttpClient(); try { request.setHeader(“Content-Type”, “application/x-www-form-urlencoded”); request.setEntity(new UrlEncodedFormEntity(getValuePairs(parameters))); HttpResponse response = defaultClient.execute(request); in = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), “UTF-8”), 8192); StringBuffer sb […]

GWT:如何使用JSON发送POST跨域请求

正如其Javadocs所建议的那样, JsonpRequestBuilder只能发送GET请求。 我需要使用相同的方法发送POST请求(对于使用JSON的跨域请求)。 有人知道任何有效的解决方案吗? 我在网上找不到任何起点。 提前致谢

在HTTPResponse Android中重定向之后

我需要遵循HTTPost给我的重定向。 当我创建一个HTTPost,并尝试读取响应时,我得到重定向的页面html。 我怎样才能解决这个问题? 码: public void parseDoc() { final HttpParams params = new BasicHttpParams(); HttpClientParams.setRedirecting(params, true); HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost( “https://secure.groupfusion.net/processlogin.php”); String HTML = “”; try { List nameValuePairs = new ArrayList(3); nameValuePairs.add(new BasicNameValuePair(“referral_page”, “/modules/gradebook/ui/gradebook.phtml?type=student_view”)); nameValuePairs.add(new BasicNameValuePair(“currDomain”, “beardenhs.knoxschools.org”)); nameValuePairs.add(new BasicNameValuePair(“username”, username .getText().toString())); nameValuePairs.add(new BasicNameValuePair(“password”, password .getText().toString())); httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); String […]