示例#1
0
 private Promise<IHttpResponse, Error> Request(string method, Uri url, Dictionary<string, string> headers, byte[] postData = null, HttpOptions options = null)
 {
     options = options == null ? new HttpOptions() : options;
     var promise = new Promise<IHttpResponse, Error>();
     var headersStr = ObjectParser.Save(headers);
     var optionsStr = ObjectParser.Save(options);
     var requestId = 0;
     var callbackInfo = ServiceProvider.Get().externalCallback.Make(
         (data) => promise.Accept(new HttpWebGLResponse(requestId, url))
     );
     if (method == "GET") {
         requestId = MakeGetRequest(url.AbsoluteUri, headersStr, optionsStr, callbackInfo);
     } else if(method == "POST") {
         var pinnedBuffer = GCHandle.Alloc(postData, GCHandleType.Pinned);
         requestId = MakePostRequest(url.AbsoluteUri, headersStr, pinnedBuffer.AddrOfPinnedObject(), postData.Length, optionsStr, callbackInfo);
         pinnedBuffer.Free();
     }
     return promise;
 }