public static Create ( Action |
||
writer | Action |
|
Результат |
static HttpResponseMessage PopulateResponse(HttpTransportAsyncResult self) { HttpResponseMessage response; Trace(self, "PopulateResponse"); var webResponse = self.webResponse; long?len = null; if (webResponse.ContentLength != -1) { len = webResponse.ContentLength; } response = new HttpResponseMessage() { Request = self.request, Content = HttpContent.Create(new HttpWebResponseInputStream(webResponse), webResponse.ContentType, len), Uri = webResponse.ResponseUri, StatusCode = webResponse.StatusCode, Method = webResponse.Method, }; if (webResponse.IsFromCache) { response.Properties.Add(CacheResponseProperty.LoadFrom(self.webRequest.CachePolicy, webResponse)); } var webResponseHeaders = webResponse.Headers; var responseHeaders = response.Headers; CopyHeadersFromHttpWebResponse(webResponseHeaders, responseHeaders); if (response.Method == "HEAD") { response.Content.LoadIntoBuffer(); } var webRequestHeaders = self.webRequest.Headers; var requestHeaders = self.request.Headers; foreach (var newHeader in webRequestHeaders.AllKeys) { if (!requestHeaders.ContainsKey(newHeader)) { requestHeaders.Add(newHeader, webRequestHeaders[newHeader]); } } if (self.settings.Cookies != null) { self.settings.Cookies.Add(webResponse.Cookies); response.Properties.Add(new CookieCollection() { webResponse.Cookies }); } return(response); }
public DataPackets.HttpResponseMessage Send(string method, Uri uri, byte[] postData, string contentType) { var content = HttpContent.Create(postData, contentType); var request = new HttpRequestMessage(method, uri, content); var response = _httpClient.Send(request); return(ToNativeResponse(response)); }
public void SendAsync(string method, Uri uri, byte[] postData, string contentType, Action <DataPackets.HttpResponseMessage> httpClientCallback) { var content = HttpContent.Create(postData, contentType); var request = new HttpRequestMessage(method, uri, content); var rawRequestData = new AsyncRequest { RawPostData = postData, RawPostDataContentType = contentType, HttpClientCallback = httpClientCallback }; _httpClient.BeginSend(request, SendAsyncEnd, rawRequestData); }
public DataPackets.HttpResponseMessage Send(string method, Uri uri, DataPackets.HttpContent postData) { System.Diagnostics.Debug.WriteLine("Request: " + uri.ToString() + " (" + method + ")"); var httpRequestMessage = new HttpRequestMessage(method, uri, HttpContent.Create(postData.Content, postData.ContentType)) { Headers = { ContentType = postData.ContentType } }; var response = _httpClient.Send(httpRequestMessage); return(ToNativeResponse(response)); }
public void SendAsync(string method, Uri uri, DataPackets.HttpContent postData, Action <DataPackets.HttpResponseMessage> httpClientCallback) { var httpRequestMessage = new HttpRequestMessage(method, uri, HttpContent.Create(postData.Content, postData.ContentType)) { Headers = { ContentType = postData.ContentType } }; var rawRequestData = new AsyncRequest { PostData = postData, HttpClientCallback = httpClientCallback }; _httpClient.BeginSend(httpRequestMessage, SendAsyncEnd, rawRequestData); }
public static HttpContent CreateJsonDataContract <T>(T value, DataContractJsonSerializer serializer, Encoding encoding, string contentType) { Action <Stream> action = (stream) => { using (var w = JsonReaderWriterFactory.CreateJsonWriter(stream, encoding, false)) { serializer.WriteObject(w, value); w.Flush(); } stream.Flush(); }; return(HttpContent.Create(action, contentType)); }
public static HttpContent Create(Action <XmlWriter> writeTo, Encoding encoding, string contentType) { if (encoding == null) { throw new ArgumentNullException("encoding"); } Action <Stream> streamWriter = (stream) => { using (var w = new XmlTextWriter(stream, encoding)) { writeTo(w); w.Flush(); } }; return(HttpContent.Create(streamWriter, contentType)); }
private static HttpRequestMessage ToMicrosoftHttpRequest(DataPackets.HttpRequestMessage httpRequestMessage) { if (httpRequestMessage.Content == null || httpRequestMessage.Content.Content.Length == 0) { return(new HttpRequestMessage(httpRequestMessage.Method, httpRequestMessage.Uri) .WithAcceptHeader(httpRequestMessage)); } return(new HttpRequestMessage(httpRequestMessage.Method, httpRequestMessage.Uri, HttpContent.Create(httpRequestMessage.Content.Content, httpRequestMessage.Content.ContentType)) .WithAcceptHeader(httpRequestMessage)); }
public static HttpContent Create(FileInfo info, string contentType) { return(HttpContent.Create(() => new FileStream(info.FullName, FileMode.Open, FileAccess.Read, FileShare.Read), contentType, info.Length)); }
public HttpContent CreateHttpContent() { var url = new UrlEncodedFormContent(this); return(HttpContent.Create(url.WriteTo, UrlEncodedFormContent.UrlEncodedContentType)); }
public HttpContent CreateHttpContent() { var mime = new MultipartMimeFormContent(this); return(HttpContent.Create(mime.WriteTo, mime.ContentType)); }