httpurlconnection

Problem simulating HTTP POST using HttpClient

帅比萌擦擦* 提交于 2019-12-02 03:58:35
问题 I am trying to programatically send a HTTP Post request using HttpClient to http://ojp.nationalrail.co.uk/en/s/planjourney/query but it is not liking the request I send it. I copied the headers and body from what Chrome browser sends so it is identical but it doesn't like what I send as the HTML mentions there's an error. <div class="padding"> <h1 class="sifr"><strong>Sorry</strong>, something went wrong</h1> <div class="error-message"> <div class="error-message-padding"> <h2>There is a

How to wait for Expect 100-continue response in Java using HttpURLConnection

吃可爱长大的小学妹 提交于 2019-12-02 03:51:46
I am stuck using HttpURLConnection to make a PUT http request to a web-server. I have some code that will make a PUT request just fine, and I can trivially include the 'Expect 100-continue Request Property' in the headers however try as I might I can't seem to make the function wait for the '100 Continue' response from the server before sending the actual http payload. I get the following (from Wireshark) PUT /post/ HTTP/1.1 User-Agent: curl/7.35.0 Accept: */* Content-Type: application/x-www-form-urlencoded Expect: 100-continue Host: somerandomdomain.info Connection: keep-alive Content-Length:

sun.net.www.protocol.https.HttpsURLConnectionImpl cannot be cast to sun.net.www.protocol.http.HttpURLConnection

允我心安 提交于 2019-12-02 03:35:38
i am using selenium library for testing purpose. But the following code giving me class cast exception. i have googled this exception but didn't get the solution. i am confused in Https connetion and http connetion. help me to solve this exception. thank you import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; import java.util.ArrayList; import java.util.List; import java.util.concurrent.TimeUnit; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import

Make HttpURLConnection load web pages with images

送分小仙女□ 提交于 2019-12-02 03:10:57
Currently I'm using HttpURLConnection for load remote web page and present to my clients (using InputStream to HttpResponse's outputStream transfer), it loads html correctly but skips images, how to fix it? Thanks You need to manipulate the HTML that way so that all resource URLs on the intranet domain are proxied as well. E.g. all of the following resource references in HTML <base href="http://intranet.com/" /> <script src="http://intranet.com/script.js"></script> <link href="http://intranet.com/style.css" /> <img src="http://intranet.com/image.png" /> <a href="http://intranet.com/page.html"

Android: How to check if Google is available?

最后都变了- 提交于 2019-12-02 02:35:06
问题 Can someone provide better and faster way to check if Google is available in Android? I have observed that connectiontimeout doesnot stop in given time_out. rather it takes more than a minute.. public static boolean isConnected(Context context){ NetworkInfo info = Connectivity.getNetworkInfo(context); return (info != null && info.isConnected()); } public boolean checkInternetConnectivity() { try { HttpURLConnection urlc = (HttpURLConnection) (new URL( "http://www.google.com").openConnection()

Android: How to check if Google is available?

折月煮酒 提交于 2019-12-02 01:56:58
Can someone provide better and faster way to check if Google is available in Android? I have observed that connectiontimeout doesnot stop in given time_out. rather it takes more than a minute.. public static boolean isConnected(Context context){ NetworkInfo info = Connectivity.getNetworkInfo(context); return (info != null && info.isConnected()); } public boolean checkInternetConnectivity() { try { HttpURLConnection urlc = (HttpURLConnection) (new URL( "http://www.google.com").openConnection()); urlc.setRequestProperty("User-Agent", "Test"); urlc.setRequestProperty("Connection", "close"); urlc

java.io.IOException: Received authentication challenge is null

99封情书 提交于 2019-12-02 01:25:48
问题 I need get a response code, but it's throw a IOException. I don't know what's the matter! try { url = new URL(urlBuilder.toString()); conn = (HttpURLConnection) url.openConnection(); conn.setDoInput(true); conn.setConnectTimeout(TIME_OUT); conn.setRequestMethod(METHOD_GET); conn.setRequestProperty("accept", "*/*"); conn.connect(); int responseCode = conn.getResponseCode(); //throw IOException:Received authentication challenge is null if (responseCode == HTTP_OK) { inStream = conn

Verifying CXF HttpAsyncClient use of use.async.http.conduit contextual property

吃可爱长大的小学妹 提交于 2019-12-02 01:18:41
问题 I am trying to make use of the CXF asynchronous HTTP client transport, through setting the "use.async.http.conduit" property, as detailed in this thread, and recommended by this CXF article. I do that using the following code: Client client = ClientProxy.getClient(wsClient); client.getRequestContext().put("use.async.http.conduit", Boolean.TRUE); As it happens, my web service call is timing out (probably due to some environmental network issue), and my client exception contains (extract): java

Problem simulating HTTP POST using HttpClient

醉酒当歌 提交于 2019-12-02 01:05:58
I am trying to programatically send a HTTP Post request using HttpClient to http://ojp.nationalrail.co.uk/en/s/planjourney/query but it is not liking the request I send it. I copied the headers and body from what Chrome browser sends so it is identical but it doesn't like what I send as the HTML mentions there's an error. <div class="padding"> <h1 class="sifr"><strong>Sorry</strong>, something went wrong</h1> <div class="error-message"> <div class="error-message-padding"> <h2>There is a problem with the page you are trying to access.</h2> <p>It is possible that it was either moved, it doesn't

How to kill a BufferedInputStream .read() call

淺唱寂寞╮ 提交于 2019-12-01 22:43:47
I'm working on writing a program to download very large files (~2GB) from a server. I've written the program to be able to resume partially finished downloads, In order to simulate a bad internet connection, I've been pulling my ethernet cord out of my router while mid-download. Unfortunately, this causes my program to hang on the following call: while((bytesRead = in.read(data)) > 0) (Where bytesRead is an int, in is a BufferedInputStream built from an HttpURLConnection, and data is a byte array). I've tried to "interrupt" the call by calling in.close() on another thread, but it has no effect