FAQ Database Discussion Community


Response from System.Net.HttpClient

c#,post,httpclient
I try to make a post request using. code: var client = new HttpClient(); // This is the postdata var postData = new List<KeyValuePair<string, string>>(); postData.Add(new KeyValuePair<string, string>("Username:", "1")); postData.Add(new KeyValuePair<string, string>("Password:", "1")); HttpContent content = new FormUrlEncodedContent(postData); client.PostAsync("http://libdiary.liberty-lab.ru/api/v1/login", content).ContinueWith( (postTask) => { postTask.Result.EnsureSuccessStatusCode(); }); But I do not know...

HttpClient GetStreamAsync and http Status codes?

c#,stream,json.net,httpclient
I wish to use streams as recommended by the json.net performance tips documentation, however I'm unable to find how to get a hold of the http status codes without the typical awaiting the HttpResponse. Is there perhaps a way of getting the status code first without reading the data? So...

Silverlight 5 fails the first time to consume a Web API 2 [clientaccesspolicy.xml]

c#,silverlight,asp.net-web-api,httpclient,webclient
Kindest regards, gentlemen and ladies. Bit or no information with regard to network my problem. I try to consume a Web API hosted on different server (localhost:/9000) by libraries: HttpClient in Silverlight 5 project (localhost:/8080). The detail is that with WebClient works perfectly, because before you get the "clientaccesspolicy.xml" file,...

Why we need to use BufferedReader instead of String while getting the response from server

java,android,httpclient,bufferedreader
I am doing an android application, Which is getting some JSON values from server. So I made some studies and develop the code for get data from server to my app. Simply I am using the below code for that. HttpResponse response; Object content = null; HttpGet httpget = new...

httpClient post call failing from a servlet with error java.lang.NoSuchMethodError:

java,servlets,post,httpclient,apache-httpclient-4.x
i am trying to make an http post call from a servlet using apache http-components client library, stuck with the following error. java.lang.NoSuchMethodError:org.apache.http.entity.StringEntity.(Ljava/lang/String;Lorg/apache/http/entity/ContentType;)V at org.apache.http.client.entity.UrlEncodedFormEntity.(UrlEncodedFormEntity.java:77) At the point where i am trying to create UrlEncodedEntity Object in the code I looked up the other post and they say, its mostly...

httpclient.execute(httpget) Doesn't seem to work (Android)

android,json,android-studio,httpclient
I'm trying to get a daily quote from http://quotesondesign.com/api/3.0/api-3.0.json?callback=json I call this method in my onCreate But when i try to execute the httpclient.execute(); it escapes to the catch statement... What am I doing wrong? I did include the <uses-permission android:name="android.permission.INTERNET" /> in my manifest file. public String getJson(){ String...

HttpClient class is deprecated

android,httpclient,deprecated
I'm working on a registration page in my android application and i've done it successfully without any errors. But i have one problem. Some classes are shown as deprecated. HttpClient httpClient = new DefaultHttpClient(); HttpContext httpContext = new BasicHttpContext(); HttpGet httpGet = new HttpGet(url); try { HttpResponse response = httpClient...

Is it possible to alter the HTTP client timeout period (cpp-netlib)?

c++,httpclient,cpp-netlib
I'm using cpp-netlib (v0.11.0) to send HTTP requests. I'd like to know if it's possible to alter the timeout period when sending an HTTP POST request. I'm running some unit tests, one of which sends an HTTP request to an address where there is no server running. An attempt to...

HttpClient request in Android application fails without any Exceptions

java,android,apache,servlets,httpclient
I have an Android application which makes calls to a java server application deployed on a Apache server located on my laptop. When testing the application at home, all the calls to the server are successful. If however, I connect to a different WiFi (in a cafe' for instance), the...

HttpClient and using proxy - constantly getting 407

c#,.net,proxy,httpclient
Here is the code: HttpClient client = null; HttpClientHandler httpClientHandler = new HttpClientHandler() { Proxy = new WebProxy(string.Format("{0}:{1}", proxyServerSettings.Address, proxyServerSettings.Port),false), PreAuthenticate = true, UseDefaultCredentials = false, }; this.httpClientHandler.Credentials = new NetworkCredential(proxyServerSettings.UserName, proxyServerSettings.Password); this.client = new HttpClient(this.httpClientHandler); And when I finally do this: HttpResponseMessage httpResponseMessage =...

windows phone 8 c# httpclient dosent send request for second time

c#,php,windows-phone-8,httpclient
i am trying for a simple app in windows phone 8.1. i have a button and on first time click it send a request to insert data into the database via url in php. on second click it delete the data from the same table in database via another url...

c# why httpClient is not opening any page in the browser

c#,asp.net,.net,httpclient
I have a console applucaiton and I want to open a asp.net page from it. I tried this: HttpClient client = new HttpClient(); client.BaseAddress = new Uri("http://localhost:9000/"); client.GetAsync("http://localhost:9000/"); but when I run the application, nothing in the browser becomes opened. why please? what did I miss?...

how to load multiple files with single HTTP request

ruby-on-rails,httpclient
In my Rails project, I send a request , these are many files what I need, Started GET "/assets/bootstrap.min.css?body=1" for 127.0.0.1 at 2015-05-29 11:55:09 +0800 Started GET "/assets/customized_bootstrap.css?body=1" for 127.0.0.1 at 2015-05-29 11:55:09 +0800 Started GET "/assets/jquery.ui.core.css?body=1" for 127.0.0.1 at 2015-05-29 11:55:09 +0800 Started GET "/assets/jquery.ui.theme.css?body=1" for 127.0.0.1 at 2015-05-29...

HttpClient ObjectContent JSON: format with root class name in json object?

c#,json,httpclient
I generate a C# class for a json source using json2csharp.com. My json is: { "email_verified": true, "user_id": "gg2323", "app_metadata": { "tc_app_user": { "user_guid": "c0fb150f6er344df98ea3a06114e1e4a", "cto_admin_a_user_id": "551294d4f6cfb46e65a5aq71", "lang": "EN", "country": "USA", "disabled": false } and my resulting C# is: public class TcAppUser { public string user_guid { get; set; }...

I need an option to HttpClient in Android to send data to PHP as it is deprecated in API 22

android,api,http-post,httpclient
Currently I'm using HttpClient, HttpPost to send data to my PHP server from an Android app but those all methods are deprecated in API 22 so what is the option to it. I searched everywhere but I didn't find anything.

HttpClient POST multiple objects/variables

c#,variables,post,httpclient
I'm using HttpClient to connect .NET project with my Web API. Thing is, that i can't make it work when sending multiple variables or objects. With one parameter i do like this: using (var client = new HttpClient()) { client.BaseAddress = new Uri("http://localhost/"); client.DefaultRequestHeaders.Accept.Clear(); int systemId = 24; var response...

BufferReader buffer = new BufferReader() Gives me an ERROR NullPointerException and It stops there with Debug

android,eclipse,nullpointerexception,httpclient,inputstreamreader
I tried running this code on Eclipse and it was me an error. I'm trying to send a HTTP to a php site and get the response as a TextView. login.setOnClickListener(new View.OnClickListener(){ @Override public void onClick(View v){ try{ test_email = email.getText().toString(); String submit = "http://androidexample.com/media/webservice/httpget.php?user=" + test_email; URI websitetarget =...

updating from HttpClient to HttpURLConnection

java,android,forms,httpclient,httpurlconnection
I've been working on an android app, and recently got all of the login code working using HttpClient. However, this code is now deprecated and no longer works. The language summary suggests replacing all HttpClient code with HttpURLConnection objects. I'm not sure how to do that though. If anyone could...

Java using HTTP client 4.5 client get statements

java,apache,httpclient
I am trying to update code from Apache HTTP client 3.1 to 4.5 and I have several methods like client.getHostConfiguration, client.getState,client.getHttpConnectionManager. All of these do not work in the newer versions of httpclient so I am wondering how to rewrite these. All I see in the HTTP client documentation is...

Execute GET request for REST API call in Java [duplicate]

java,curl,httpclient,httpurlconnection
This question already has an answer here: How do I do a HTTP GET in Java? [duplicate] 4 answers I want to call REST API for GET request in Java. I want to send some query parameters with the request. How to do it? The format of the curl...

HTTPNetStreamInfo::_readStreamClientCallBack(__CFReadStream*, unsigned long) increases memory allocation

ios,memory,memory-management,xamarin,httpclient
I am trying to download large video file with httpClient post method. I am working Xamarin.iOS, but it seems to be issue of iOS (NSURLConnection/session) as the Xamarin codes convert it into native one. My device is having IOS8.1. A memory is kept increasing when I try to download that...

Custom httpClient filter through exception when server is down

c#,multithreading,windows-store-apps,windows-phone-8.1,httpclient
I am new to windows store apps. I am trying to add custom filter to HttpClient it works fine but when the server is down the catch block return null which causes the system to through System.AccessViolationException. how should i handle that case. public IAsyncOperationWithProgress<HttpResponseMessage, HttpProgress> SendRequestAsync(HttpRequestMessage request) { HttpResponseMessage...

Any Apache HttpClient 4.4 Example for trust self signed certificates

java,ssl,httpclient
I changed HttpClient version from old version to the new 4.4. And got many deprecated method and Class. The original codes can trust self signed certificates and I want to replace to new method and Class. Could any one give me a guide line how to replace or any example...

https post request using httpClient and cert.em

java,ssl,https,httpclient,ca
I have a piece of code that sends a payload to a https endpoint(or should). I also have a CA chain in .pem format and this how in code I try and add that use it to do the POST. HttpClient client = new HttpClient(); Gson gson = new GsonBuilder().setPrettyPrinting().create();...

How to configure the number of allowed pending requests in Apache async client

java,apache,httpclient,apache-httpclient-4.x
I'm developing an HTTP client application, using Apache httpasyncclient version 4.0.2. I would like to configure the maximum number of pending requests. Initially I assumed this number is the same as the maximum number of connections. I set this to 20 in the following way: final CloseableHttpAsyncClient httpclient; In the...

StringContent vs ObjectContent

c#,json,serialization,httpclient,dotnet-httpclient
I am using System.Net.Http's HttpClient to call a REST API with "POST" using the following code: using (HttpRequestMessage requestMessage = new HttpRequestMessage( HttpMethod.Post, new Uri(request)) { }) { response = await httpClient.PostAsync(request, objectContent); } The "objectContent" is currently this - objectContent = new ObjectContent(jsonContent.GetType(), jsonContent, new JsonMediaTypeFormatter()); I was wondering...

Apache Httpclient Connection not Released

java,httpclient
I am using spring rest template to send REST request with apache http client 4.2.1 intergrated. As we need send request to multiple server, added PoolingClientConnectionManager to manager the connections. Set the max per route to 5 connectionManager.setDefaultMaxPerRoute(5) While after the system running for few days, we found that the...

Unable to get data at first click in android webview with server communication

javascript,android,html,httpclient
I am calling this method from JavaScript. For the first time, it is giving null. But from the second time onwards, the data is coming. Please help me. @SuppressLint("JavascriptInterface") public String loadClickedData() { pDialog = ProgressDialog.show(this, "dialog title", "dialog message", true); new HttpAsyncTaskClickedData() .execute("http://192.168.0.9/btrepo/btrepo/android_api.php"); return bdb.getmPosIdData(); } Here we are...

HttpClient returning special characters but nothing readable

c#,wpf,async-await,httpclient
I am trying to download a webpage using async and await and HttpClient, but am getting only a string full of special characters... Code is like.. static async void DownloadPageAsync(string url) { HttpClient client = new HttpClient(); client.DefaultRequestHeaders.TryAddWithoutValidation("Accept", "text/html,application/xhtml+xml,application/xml"); client.DefaultRequestHeaders.TryAddWithoutValidation("Accept-Encoding", "gzip, deflate"); client.DefaultRequestHeaders.TryAddWithoutValidation("User-Agent", "Mozilla/5.0 (Windows NT 6.2; WOW64;...

How to set timeout to JAX-RS client with CXF

java,web-services,rest,cxf,httpclient
I am working on a Rest Client and I am using CXF with JAX-RS. The problem that I have is that I cannot find any way to override the default timeout values of the client. A simple client: Client client = ClientBuilder.newClient(); WebTarget target = client.target("http://localhost:8080/MyApp"); target = target.path("jsp/Test.jsp"); Response...

Windows Store Apps, download multiple files with threads

c#,multithreading,windows-store-apps,httpclient
I have this following method that I use to download a file's content: public async Task<String> DownloadFileService(String filePath, string id) { string resposta = string.Empty; try { using (var httpClient = new HttpClient { BaseAddress = Constants.baseAddress }) { string token = App.Current.Resources["token"] as string; httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);...

POST single string Web API

c#,post,httpclient,web-api
I'm trying to make an application for Windows which acts like a server for a mobile application (PhoneGap). This application is like a remote for the server application, it invokes methods in which their turn do things. After long searching and trying to see which components can work together I...

Unable to find valid certification path to requested target - java

java,httpclient,sslhandshakeexception
I'm trying to connect to a website using a HttpClient object. It works fine for websites we normally use(Like google). But there is a web site, when I try to connect, my program gives this error.. javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to...

Parse the json objects inside json Array in Android?

android,json,android-asynctask,httpclient
I am trying to parse json values into my Android application and put the result in a lisview. There is my JSON result: [ {"dateticket": "12/02/2015", "description": "kkkkkk", "etat": "suivi", "idticket": 32, "nomfichier": "contrat", "objet": "contrat", "priorite": "first"}, {"dateticket": null, "description": null, "etat": "en cours", "idticket": 98, "nomfichier": "lotfi", "objet":...

Can't set Content-Type header

c#,windows-phone-8.1,httpclient,flurl
I'm having trouble setting the Content-Type on HttpClient. I followed along this question: How do you set the Content-Type header for an HttpClient request? But still no luck. String rcString = JsonConvert.SerializeObject(new RoadsmartChecks() { userguid = user_guid, coords = coordinates, radius = (radius * 100) + "" }, ROADSMART_JSON_FORMAT, JSONNET_SETTINGS);...

HTTP CONNECT method with Android

android,http,proxy,httpclient,connect
I want to extend an existing Android app which sets up a http connection to a remote device which it sends commands to and receives values from. The feature consists of a tunneled connection via a custom proxy server that has been set up. I have the http header format...

CURL in JAVA - Could not resolve host : POST

java,post,curl,httpclient,processbuilder
I have been successfully able to perform CURL commands from the CMD in my Windows PC by installing curl for Windows. Similarly, I have been able to get them working in my JAVA application by using ProcessBuilder and Process to create Operating System process. In particular, I need to execute...

Jasper server rest service returns unauthorized

c#,jasper-reports,httpclient,jasperserver
Using .NET Http client i login to jasper server. HttpResponseMessage loginResponse = loginClient.PostAsync("http://localhost:8080/jasperserver/rest/login", formContent).Result; IEnumerable<string> jaspsessid = loginResponse.Headers.GetValues("Set-Cookie"); Using above session id i pass to next request. HttpClient httpClient = new HttpClient(); httpClient.DefaultRequestHeaders.Add("Cookie", jaspsessid); httpClient.DefaultRequestHeaders.Accept.Add(new...

Android Java: string returns empty while it's not?

java,android,httpclient
I'm trying to grab the HTML code of a webpage with HttpClient() in Android. getbodyHtml returns empty, while in the output I see the HTML code printed fine. What am I doing wrong? class GetResult implements Runnable { public volatile String bodyHtml; public volatile boolean finished = false; @Override public...

Converting HttpClient version 3 ProtocolSocketFactory use to version 4

apache,httpclient
I have some code that uses HttpClient version 3. I would like to come up with a version 4 equivalent. I believe 4.0 but any version 4 would be helpful. ProtocolSocketFactory psf = myObj.getPSF(); httpClient.getHostConfiguration().setHost(host, port, new Protocol("http", psf, 80)); ...

How to force the http client to not handle the authentication challenges automatically in httpClient 4.3.x?

java,httpclient,apache-httpclient-4.x
I am migrating my httpclient 3.x to httpclient 4.3.x. With httpClient 3.x I used setDoAuthentication(false) which ensured that the method would not try to handle the authentication challenges automatically. How can I set the same functionality with httpClient 4.3.x? I already went through the javadocs of httpmethods and httpclient and...

Using HttpClient in ASP.NET 5 app

asp.net,httpclient,asp.net-5
I am trying to build an app with ASP.NET 5 (aka vNext). I need to call a third-party REST-API. Traditionally, I would use HttpClient. However, I can't seem to get it to work. In my project.json file I have: "dependencies": { "Microsoft.Net.Http.Client": "1.0.0-*" } When I run dnu restore, I...

How to use HttpClient to Post with Authentication

c#,.net,httpclient
I am trying to do the following curl (which works for me) in C# using HttpClient. curl -X POST http://www.somehosturl.com \ -u <client-id>:<client-secret> \ -d 'grant_type=password' \ -d 'username=<email>' \ -d 'password=<password>' \ -d 'scope=all The C# Code: HttpClientHandler handler = new HttpClientHandler { Credentials = new System.Net.NetworkCredential ("my_client_id", "my_client_secret")...

Timeout waiting for connection from pool - despite single SolrServer

solr,httpclient,spring-data,solrj,spring-data-solr
We are having problems with our solrServer client's connection pool running out of connections in no time, even when using a pool of several hundred (we've tried 1024, just for good measure). From what I've read, the following exception can be caused by not using a singleton HttpSolrServer object. However,...