/// <summary> /// Initializes a new instance of the <see cref="WebRequest"/> class. /// </summary> /// <param name="type">Specifies the type of web request.</param> /// <param name="destination">Specifies the destination of the request.</param> protected WebRequest(WebRequestType type, Uri destination) { Headers = new NameValueCollection(); AutoRedirect = true; Type = type; Destination = destination; }
public Response(HttpWebRequest request, WebRequestType requestType) { _requestUri = request.RequestUri; _origin = request.Headers["Origin"]; _referer = request.Referer; _response = HttpStatusCode.OK; _responseLocation = null; switch (requestType) { case WebRequestType.RequestVerificationToken: _responseBody = App.myLB.strHTML_RequestVerificationToken; _responseUri = new Uri(App.myLB.strURL_RequestVerificationToken, UriKind.Absolute); break; case WebRequestType.VerficationCode: _responseBody = App.myLB.strHTML_VerficationCode; _responseUri = new Uri(App.myLB.strURL_VerficationCode, UriKind.Absolute); break; case WebRequestType.Result: _responseBody = App.myLB.strHTML_Result; _responseUri = new Uri(App.myLB.strURL_Result, UriKind.Absolute); break; } }
public AdvancedCreatorViewModel() { _text = string.Empty; _type = string.Empty; _url = string.Empty; _requestType = WebRequestType.Post; }
/// <summary> /// Initializes a new instance of the <see cref="WebRequest"/> class. /// </summary> /// <param name="type">Specifies the type of web request.</param> /// <param name="destination">Specifies the destination of the request.</param> protected WebRequest( WebRequestType type, Uri destination ) { Headers = new NameValueCollection(); AutoRedirect = true; Type = type; Destination = destination; }
public static CommResult SendRequest(Uri url, WebRequestType type, string data = "") { CommResult result = new CommResult(); try { WebClientTimeout wc = new WebClientTimeout { Proxy = null, Timeout = _timeout }; string Method = string.Empty; string received = string.Empty; switch (type) { case WebRequestType.PUT: Method = "PUT"; received = wc.UploadString(url, Method, data); break; case WebRequestType.GET: Method = "GET"; var bytes = wc.DownloadData(url); UTF8Encoding utf8 = new UTF8Encoding(); received = utf8.GetString(bytes); break; case WebRequestType.POST: Method = "POST"; received = wc.UploadString(url, Method, data); break; case WebRequestType.DELETE: Method = "DELETE"; received = wc.UploadString(url, Method, data); break; } if (received != string.Empty) { result.status = WebExceptionStatus.Success; result.data = received; } lastjson = received; } catch (WebException ex) { result.status = ex.Status; result.data = "{}"; } catch (Exception) { lastjson = null; } return(result); }
public static async Task <string> Send(WebRequestType webType, string urlparams, HttpContent content = null) { string requestresult = string.Empty; try { string url = string.Format(Properties.Resources.url, Properties.Resources.merchant_id, urlparams); ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; using (HttpClient hc = new HttpClient()) { UTF8Encoding encoding = new UTF8Encoding(); var bytes = encoding.GetBytes( String.Concat(Properties.Resources.merchant_id, ":", Properties.Resources.api_key)); var auth = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(bytes)); hc.DefaultRequestHeaders.Authorization = auth; hc.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); HttpResponseMessage response = null; switch (webType) { case WebRequestType.Delete: response = hc.DeleteAsync(url).Result; break; case WebRequestType.Get: response = hc.GetAsync(url).Result; break; case WebRequestType.Post: response = hc.PostAsync(url, content).Result; break; case WebRequestType.Put: response = hc.PutAsync(url, content).Result; break; } Task <Stream> streamTask = response.Content.ReadAsStreamAsync(); using (Stream stream = streamTask.Result) { using (MemoryStream memoryStream = new MemoryStream()) { await stream.CopyToAsync((Stream)memoryStream); byte[] data = memoryStream.ToArray(); requestresult = Encoding.UTF8.GetString(data, 0, data.Length); } } return(requestresult); } } catch (Exception) { requestresult = "[{IsError: true}]"; return(requestresult); } }
/// <summary> /// Send a raw json command to the bridge without altering the bridge lastmessages /// </summary> /// <param name="url">url to send the command to.</param> /// <param name="data">raw json data string</param> /// <param name="type">type of command.</param> /// <returns>json test resulting of the command.</returns> public async Task <string> SendRawCommandAsyncTask(string url, string data, WebRequestType type) { CommResult comres = await Comm.SendRequestAsyncTask(new Uri(url), type, data); if (comres.Status == WebExceptionStatus.Success) { if (type != WebRequestType.Get) { LastCommandMessages.AddMessage(Serializer.DeserializeToObject <List <IMessage> >(comres.Data)); } return(comres.Data); } ProcessCommandFailure(url, comres.Status); return(null); }
/// <summary> /// Send a raw json command to the bridge without altering the bridge lastmessages /// </summary> /// <param name="url">url to send the command to.</param> /// <param name="data">raw json data string</param> /// <param name="type">type of command.</param> /// <returns>json test resulting of the command.</returns> public async Task <string> SendRawCommandAsyncTask(string url, string data, WebRequestType type) { HttpResult comres = await HueHttpClient.SendRequestAsyncTask(new Uri(url), type, data); if (comres.Success) { if (type != WebRequestType.Get) { LastCommandMessages.AddMessage(Serializer.DeserializeToObject <List <IMessage> >(comres.Data)); } return(comres.Data); } BridgeNotResponding?.Invoke(this, new BridgeNotRespondingEventArgs(this, url, WebExceptionStatus.NameResolutionFailure)); return(null); }
public BaseWebRequest GetWebRequest(WebRequestType type, string name) { BaseWebRequest webRequest = null; List <BaseWebRequest> list; if (webrequests.TryGetValue(type, out list)) { foreach (BaseWebRequest b in list) { if (b.name == name) { webRequest = b; } } } return(webRequest); }
public void UnRegister(WebRequestType type, string name) { List <BaseWebRequest> list; if (webrequests.TryGetValue(type, out list)) { foreach (BaseWebRequest b in list) { if (b.name == name) { list.Remove(b); } } if (list.Count <= 0) { list.Clear(); webrequests.Remove(type); } } }
//Method to format our web server responses based on the type of request. public string HttpRequestHandler(WebRequestType type, string deviceIpAddress) { StringBuilder ControllerResponse = new StringBuilder(); switch (type) { case WebRequestType.DashboardDataExtract: ControllerResponse.Append(JsonConvert.SerializeObject(AtwaterMonitorModel.GetUPSDeviceEnumerator(), Formatting.None).ToString()); break; case WebRequestType.GetTemperatureHistory: ControllerResponse.Append(GetTemperatureHistory(deviceIpAddress)); //TODO: Remove this Console.WriteLine(ControllerResponse.ToString()); break; default: break; } return(ControllerResponse.ToString()); }
private IEnumerator SendWebRequest(WebRequestType type, string name) { BaseWebRequest webRequestInfo = GetWebRequest(type, name); using (UnityWebRequest unityWeb = UnityWebRequest.Get(webRequestInfo.uri)) { webRequestInfo.OnPreWebRequest(unityWeb);//开始加载 UnityWebRequestAsyncOperation async = unityWeb.SendWebRequest(); webRequestInfo.OnUpdateWebRequest(async); yield return(async); if (!unityWeb.isHttpError && !unityWeb.isNetworkError)//加载结束 { webRequestInfo.OnFinished(unityWeb.downloadHandler); } else { Debug.Log(unityWeb.error); } unityWeb.Dispose(); } }
public WebRequestStream(WebRequestType type, string uri, string name) : base(type, uri, name) { }
/// <summary> /// Initializes a new instance of the <see cref="WebRequest"/> class. /// </summary> /// <param name="type">Specifies the type of web request.</param> protected WebRequest(WebRequestType type) : this(type, new Uri("about:blank")) { }
public WebRequestHelper(string url, WebRequestType type) { Init(url, type); }
private void Init(string url, WebRequestType type) { _url = url; _type = type; _timeoutMilliSec = Util.DefaultWebRequestTimeoutSec * 1000; _header = new Dictionary<string, string>(); _parameter = new Dictionary<string, string>(); }
public void SendRequest(WebRequestType type, string name) { Main.instance.StartCoroutine(SendWebRequest(type, name)); }
public WebRequestTexture(WebRequestType type, string uri, string name) : base(type, uri, name) { }
/// <summary> /// Initializes a new instance of the <see cref="WebRequest"/> class. /// </summary> /// <param name="type">Specifies the type of web request.</param> protected WebRequest( WebRequestType type ) : this(type, new Uri( "about:blank" )) { }
public BaseWebRequest(WebRequestType type, string uri, string name) { mWebRequestType = type; mUrl = uri; mName = name; }
public static void DrawStandardSettingsSubPanel() { float labelWidth = 160; if (_foundUnknownTitleId && (_TitleId != _prevTitleId)) { _prevTitleId = _TitleId; } if (_selectedStudioIndex != _prevSelectedStudioIndex) { // handle our _OVERRIDE_ STATE FIRST if (_selectedStudioIndex == 0) { _prevSelectedStudioIndex = 0; _selectedTitleIdIndex = 0; _foundUnknownTitleId = true; _TitleId = string.Empty; #if ENABLE_PLAYFABADMIN_API || ENABLE_PLAYFABSERVER_API _DeveloperSecretKey = string.Empty; #endif } else { _foundUnknownTitleId = false; _selectedTitleIdIndex = _selectedTitleIdIndex > PlayFabEditorDataService.accountDetails.studios[_selectedStudioIndex - 1].Titles.Length ? 0 : _selectedTitleIdIndex; // reset our titles index CompoundTitlesList(); _prevSelectedStudioIndex = _selectedStudioIndex; } } if (_selectedTitleIdIndex != _prevSelectedTitleIdIndex) { // this changed since the last loop _prevSelectedTitleIdIndex = _selectedStudioIndex; #if ENABLE_PLAYFABADMIN_API || ENABLE_PLAYFABSERVER_API _DeveloperSecretKey = PlayFabEditorDataService.accountDetails.studios[_selectedStudioIndex - 1].Titles[_selectedTitleIdIndex].SecretKey; #endif } GUILayout.BeginVertical(PlayFabEditorHelper.uiStyle.GetStyle("gpStyleGray1"), GUILayout.ExpandWidth(true)); if (_foundUnknownTitleId) { GUILayout.BeginHorizontal(PlayFabEditorHelper.uiStyle.GetStyle("gpStyleClear")); GUILayout.Label("You are using a TitleId to which you are not a memeber. A title administrator can approve access for your account.", PlayFabEditorHelper.uiStyle.GetStyle("orTxt")); GUILayout.EndHorizontal(); } if (studioOptions != null && studioOptions.Length > 0) { GUILayout.BeginHorizontal(PlayFabEditorHelper.uiStyle.GetStyle("gpStyleClear")); EditorGUILayout.LabelField("STUDIO: ", PlayFabEditorHelper.uiStyle.GetStyle("labelStyle"), GUILayout.Width(labelWidth)); _selectedStudioIndex = EditorGUILayout.Popup(_selectedStudioIndex, studioOptions, PlayFabEditorHelper.uiStyle.GetStyle("TextField"), GUILayout.MinHeight(25)); GUILayout.EndHorizontal(); } // SPECIAL HANDLING FOR THESE FIELDS -- How we show the following depends on the data state (TitleId, DevKey & Studio) if (_foundUnknownTitleId || _selectedStudioIndex == 0) { GUILayout.BeginHorizontal(PlayFabEditorHelper.uiStyle.GetStyle("gpStyleClear")); EditorGUILayout.LabelField("TITLE ID: ", PlayFabEditorHelper.uiStyle.GetStyle("labelStyle"), GUILayout.Width(labelWidth)); _TitleId = EditorGUILayout.TextField(_TitleId, PlayFabEditorHelper.uiStyle.GetStyle("TextField"), GUILayout.MinHeight(25)); GUILayout.EndHorizontal(); #if ENABLE_PLAYFABADMIN_API || ENABLE_PLAYFABSERVER_API GUILayout.BeginHorizontal(PlayFabEditorHelper.uiStyle.GetStyle("gpStyleClear")); EditorGUILayout.LabelField("DEVELOPER SECRET KEY: ", PlayFabEditorHelper.uiStyle.GetStyle("labelStyle"), GUILayout.Width(labelWidth)); _DeveloperSecretKey = EditorGUILayout.TextField(_DeveloperSecretKey, PlayFabEditorHelper.uiStyle.GetStyle("TextField"), GUILayout.MinHeight(25)); GUILayout.EndHorizontal(); #endif } else { if (titleOptions != null && titleOptions.Length > 0) { GUILayout.BeginHorizontal(PlayFabEditorHelper.uiStyle.GetStyle("gpStyleClear")); EditorGUILayout.LabelField("TITLE ID: ", PlayFabEditorHelper.uiStyle.GetStyle("labelStyle"), GUILayout.Width(labelWidth)); _selectedTitleIdIndex = EditorGUILayout.Popup(_selectedTitleIdIndex, titleOptions, PlayFabEditorHelper.uiStyle.GetStyle("TextField"), GUILayout.MinHeight(25)); GUILayout.EndHorizontal(); } #if ENABLE_PLAYFABADMIN_API || ENABLE_PLAYFABSERVER_API GUILayout.BeginHorizontal(PlayFabEditorHelper.uiStyle.GetStyle("gpStyleClear")); EditorGUILayout.LabelField("DEVELOPER SECRET KEY: ", PlayFabEditorHelper.uiStyle.GetStyle("labelStyle"), GUILayout.Width(labelWidth)); _DeveloperSecretKey = EditorGUILayout.TextField(_DeveloperSecretKey, PlayFabEditorHelper.uiStyle.GetStyle("TextField"), GUILayout.MinHeight(25)); GUILayout.EndHorizontal(); #endif } // ------------------------------------------------------------------------------------------------------------------------------------------------ GUILayout.BeginHorizontal(PlayFabEditorHelper.uiStyle.GetStyle("gpStyleClear")); EditorGUILayout.LabelField("REQUEST TYPE: ", PlayFabEditorHelper.uiStyle.GetStyle("labelStyle"), GUILayout.MaxWidth(labelWidth)); _RequestType = (WebRequestType)EditorGUILayout.EnumPopup(_RequestType, PlayFabEditorHelper.uiStyle.GetStyle("TextField"), GUILayout.Height(25)); GUILayout.EndHorizontal(); if (_RequestType == WebRequestType.HttpWebRequest) { using (FixedWidthLabel fwl = new FixedWidthLabel(new GUIContent("REQUEST TIMEOUT: "), PlayFabEditorHelper.uiStyle.GetStyle("labelStyle"))) { GUILayout.Space(labelWidth - fwl.fieldWidth); _RequestTimeOut = EditorGUILayout.IntField(_RequestTimeOut, PlayFabEditorHelper.uiStyle.GetStyle("TextField"), GUILayout.MinHeight(25)); } using (FixedWidthLabel fwl = new FixedWidthLabel(new GUIContent("KEEP ALIVE: "), PlayFabEditorHelper.uiStyle.GetStyle("labelStyle"))) { GUILayout.Space(labelWidth - fwl.fieldWidth); _KeepAlive = EditorGUILayout.Toggle(_KeepAlive, PlayFabEditorHelper.uiStyle.GetStyle("Toggle"), GUILayout.MinHeight(25)); } } GUILayout.BeginHorizontal(PlayFabEditorHelper.uiStyle.GetStyle("gpStyleClear")); EditorGUILayout.LabelField("COMPRESS API DATA: ", PlayFabEditorHelper.uiStyle.GetStyle("labelStyle"), GUILayout.MaxWidth(labelWidth)); _CompressApiData = EditorGUILayout.Toggle(_CompressApiData, PlayFabEditorHelper.uiStyle.GetStyle("Toggle"), GUILayout.MinHeight(25)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(PlayFabEditorHelper.uiStyle.GetStyle("gpStyleClear")); var buttonWidth = 100; GUILayout.Space(EditorGUIUtility.currentViewWidth - buttonWidth); if (GUILayout.Button("SAVE", PlayFabEditorHelper.uiStyle.GetStyle("Button"), GUILayout.MinHeight(32), GUILayout.MaxWidth(buttonWidth))) { OnSaveSettings(); } GUILayout.EndHorizontal(); GUILayout.EndVertical(); }
/// <summary> /// Send a raw json command to the bridge. /// </summary> /// <param name="url">url to send the command to.</param> /// <param name="data">raw json data string</param> /// <param name="type">type of command.</param> /// <returns>json test resulting of the command.</returns> public string SendRawCommand(string url, string data, WebRequestType type) { CommResult comres = Communication.SendRequest(new Uri(url), type, data); return(comres.data); }
public WebRequestText(WebRequestType type, string uri, string name, Action <string> action) : base(type, uri, name) { }
public WebRequestTexture(WebRequestType type, string uri, string name, Action <Texture2D> action) : base(type, uri, name) { this.action = action; }
public static string GetMethodName(WebRequestType method) => Enum.GetName(typeof(WebRequestType), method);