request-headers

Adding Authorization Header to Web Reference

别来无恙 提交于 2019-12-04 10:22:07
问题 I'm attempting to make requests to a client's web service (I don't know the underlying platform at the client). I've consumed the client's WSDL in Visual Studio 2010 using "Add Web Reference" and generated my proxy class (called "ContactService"). I now need to add an authorization header like the one below to my service request. Header=Authorization & Value=Basic 12345678901234567890 (the "123456..." value above is just placeholder) ContactService service = new ContactService(); //not sure

Add request headers with WebClient C#

感情迁移 提交于 2019-12-03 08:32:43
I have the following code with which I download a web-page into a byte array and then print it with Response.Write: WebClient client = new WebClient(); byte[] data = client.DownloadData(requestUri); /*********** Init response headers ********/ WebHeaderCollection responseHeaders = client.ResponseHeaders; for (int i = 0; i < responseHeaders.Count; i++) { Response.Headers.Add(responseHeaders.GetKey(i), responseHeaders[i]); } /***************************************************/ Besides of the response headers, I need to add request headers as well. I try to do it with the following code: /******

How to set the content-type of request header when using Fetch APi

£可爱£侵袭症+ 提交于 2019-12-03 06:28:36
问题 I am using npm 'isomorphic-fetch' to send requests. The problem I am experiencing is I am unable to set the content-type of the request header. I set a content type of application/json , however the request header are being set to text/plain. import 'isomorphic-fetch'; sendRequest(url, method, body) { const options = { method: method, headers:{'content-type': 'application/json'}, mode: 'no-cors' }; options.body = JSON.stringify(body); return fetch(url, options); } When I examine the request

How to set the content-type of request header when using Fetch APi

我只是一个虾纸丫 提交于 2019-12-02 21:39:38
I am using npm 'isomorphic-fetch' to send requests. The problem I am experiencing is I am unable to set the content-type of the request header. I set a content type of application/json , however the request header are being set to text/plain. import 'isomorphic-fetch'; sendRequest(url, method, body) { const options = { method: method, headers:{'content-type': 'application/json'}, mode: 'no-cors' }; options.body = JSON.stringify(body); return fetch(url, options); } When I examine the request in my browser the content type is o : content-type:text/plain;charset=UTF-8 Can anyone explain why I am

Send XMLHttpRequest with both Header and FormData

谁说胖子不能爱 提交于 2019-12-02 10:31:32
问题 I am trying to send a XMLHttpRequest with a header and add a FormData. Is there an (elegant) way i can do something like this: var formData = new FormData(); formData.append("file", file); var xhr = new XMLHttpRequest(); xhr.open("POST", "/ajax_gateway.php?mod=fileupload", true); xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded") xhr.send(formData, "token=add"); 回答1: You cannot specify the Content-Type header when sending FormData because that header automatically gets

Send XMLHttpRequest with both Header and FormData

醉酒当歌 提交于 2019-12-02 06:39:10
I am trying to send a XMLHttpRequest with a header and add a FormData. Is there an (elegant) way i can do something like this: var formData = new FormData(); formData.append("file", file); var xhr = new XMLHttpRequest(); xhr.open("POST", "/ajax_gateway.php?mod=fileupload", true); xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded") xhr.send(formData, "token=add"); You cannot specify the Content-Type header when sending FormData because that header automatically gets set to "multipart/form-data" by the browser. You can set other headers though, try this: var formData = new

How to add header to request in Jquery Ajax?

余生颓废 提交于 2019-11-30 12:08:05
I'm trying to add header to request in Ajax with JQuery. Below is the code :- $.ajax({ type: "POST", contentType: "application/json", url: "http://localhost:8080/core-service/services/v1.0/patients/registerPatients", data: JSON.stringify(patientDTO), //crossDomain : true, dataType: 'json', headers: {"X-AUTH-TOKEN" : tokken}, success: function(patientDTO) { console.log("SUCCESS: ", patientDTO); /* location.href = "fieldagentHRA.html";*/ if (typeof(Storage) !== "undefined") { localStorage.setItem("patUrn", patientDTO.data); location.href="fieldagentHRA.html"; } }, error: function(e) { console

When do browsers send application/octet-stream as Content-Type?

白昼怎懂夜的黑 提交于 2019-11-30 08:22:45
问题 I'm developing a file upload with JSF. The application saves three dates about the file: Filename Bytes Content-Type as submitted by the browser. My problem is that some files are saved with content type = application/octet-stream even if they are *.doc files oder *.pdf . When does the browser submits such a content type? I would like to clean up the database so I need to know when the browser information are incorrect. 回答1: Ignore the value sent by the browser. This is indeed dependent on

Modify request headers per request C# HttpClient PCL

青春壹個敷衍的年華 提交于 2019-11-30 04:18:41
I'm currently using the System.Net.Http.HttpClient for cross platform support. I read that it is not a good practice to instantiate a HttpClient object for each request and that you should reuse it whenever possible. Now I have a problem while writing a client library for a service. Some API calls need to have a specific header, some MUST not include this specific header. It seems that I can only manipulate the "DefaultRequestHeaders" which will be send with each request. Is there an option when actually making the request with e.g. "client.PostAsync()" to modify the headers only for the

How to add header to request in Jquery Ajax?

半世苍凉 提交于 2019-11-29 17:23:04
问题 I'm trying to add header to request in Ajax with JQuery. Below is the code :- $.ajax({ type: "POST", contentType: "application/json", url: "http://localhost:8080/core-service/services/v1.0/patients/registerPatients", data: JSON.stringify(patientDTO), //crossDomain : true, dataType: 'json', headers: {"X-AUTH-TOKEN" : tokken}, success: function(patientDTO) { console.log("SUCCESS: ", patientDTO); /* location.href = "fieldagentHRA.html";*/ if (typeof(Storage) !== "undefined") { localStorage