Tag: http status code 302

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 […]

HttpResponse代码302

我正在使用模拟器BB 8900.我正在尝试连接到url并获得响应代码302.这是什么意思? 这是我的代码片段: import javax.microedition.io.Connector; import javax.microedition.io.HttpConnection; ….. connection = (HttpConnection)Connector.open(url); responseCode = connection.getResponseCode();

HTTP Builder / Groovy – 丢失302(重定向)处理?

我在这里阅读http://groovy.codehaus.org/modules/http-builder/doc/handlers.html “在响应发送重定向状态代码的情况下,这由Apache HttpClient内部处理,默认情况下只是通过将请求重新发送到新url来关注重定向。您无需执行任何特殊操作即可遵循302响应。“ 当我只使用没有闭包的get()或post()方法时,这似乎工作正常。 但是,当我使用一个闭包时,我似乎失去了302处理。 我有办法自己处理吗? 谢谢 ps这是我的日志输出,显示它是302响应 [java] FINER: resp.statusLine: “HTTP/1.1 302 Found” 这是相关的代码: // Copyright (C) 2010 Misha Koshelev. All Rights Reserved. package com.mksoft.fbbday.main import groovyx.net.http.ContentType import java.util.logging.Level import java.util.logging.Logger class HTTPBuilder { def dataDirectory HTTPBuilder(dataDirectory) { this.dataDirectory=dataDirectory } // Main logic def logger=Logger.getLogger(this.class.name) def closure={resp,reader-> logger.finer(“resp.statusLine: \”${resp.statusLine}\””) if (logger.isLoggable(Level.FINEST)) { def respHeadersString=’Headers:’; […]

当我调用connect()时,Java HttpURLConnection无法连接

我正在尝试编写一个程序来对我的webapp进行自动化测试。 为此,我使用HttpURLConnection打开连接。 我正在尝试测试的其中一个页面执行302重定向。 我的测试代码如下所示: URL currentUrl = new URL(urlToSend); HttpURLConnection connection = (HttpURLConnection) currentUrl.openConnection(); connection.connect(); system.out.println(connection.getURL().toString()); 所以,假设urlToSend是http://www.foo.com/bar.jsp ,并且该页面将您重定向到http://www.foo.com/quux.jsp 。 我的println语句应该打印出来http://www.foo.com/quux.jsp ,对吗? 错误。 重定向永远不会发生,并打印出原始URL。 但是,如果我通过调用connection.getResponseCode()更改切换出connection.connect()行,它就会神奇地起作用。 URL currentUrl = new URL(urlToSend); HttpURLConnection connection = (HttpURLConnection) currentUrl.openConnection(); //connection.connect(); connection.getResponseCode(); system.out.println(connection.getURL().toString()); 为什么我看到这种行为? 我做错了吗? 谢谢您的帮助。