예제 #1
0
    static IEnumerator worker(WWW www, WebResponseHandler responseHandler, WebErrorHandler errorHandler)
    {
        yield return(www);

        if (www.error != null)
        {
//			Debug.Log ("Request to " + www.url + " failed");
            Debug.Log("WWW error: " + www.error);
            Debug.Log(www.responseHeaders);
            Debug.Log(www.url);
            Debug.Log(www.ToString());
            Debug.Log(www.text);
            // Debug.Log(www.data);
            if (errorHandler != null)
            {
                errorHandler(www.error);
            }
        }
        else
        {
//			Debug.Log ("Request to " + www.url + " succeeded");
            if (responseHandler != null)
            {
                responseHandler(www.text);
            }
        }
    }
예제 #2
0
    /*------------------------------------------------------------------------------*/
    IEnumerator PostJsonRequest(string url, object data, WebResponseHandler <string> onResponse)
    {
        var jsonString = JsonUtility.ToJson(data);
//		var req = CreatePostJSONRequest(url, data);
//		var req = UnityWebRequest.Post(url, jsonString);
//		req.downloadHandler = new DownloadHandlerJson();
//		req.method = "POST";
        var req = UWebRequest.UWebRequestCreator.PostJson(url, jsonString, new DownloadHandlerJson());        //

        yield return(req.Send());

        //
        if (req.isError)
        {
            //Handle Error
            Debug.LogFormat("request {0} error {1}", url, req.error);
//			yield break;
        }
        if (req.responseCode != 200)
        {
            Debug.LogFormat("request {0} web error {1}", url, req.responseCode);
//			yield break;
        }
        //
        var jsonStr = DownloadHandlerJson.GetContent(req);
        //
        var response = new UWebResponse <string>(url, req.responseCode, req.error, jsonStr);

        onResponse(response);
        Debug.LogFormat("Web request {0} succes.\nResponse: {1}", url, jsonStr.ToString());
//		this.textResponse.text = jsonStr;
        //
    }
예제 #3
0
    static IEnumerator worker( WWW www, WebResponseHandler responseHandler, WebErrorHandler errorHandler)
    {
        yield return www;

        if( www.error != null ) {
        //			Debug.Log ("Request to " + www.url + " failed");
            Debug.Log( "WWW error: " + www.error );
            if (errorHandler != null)
                errorHandler(www.error);
        } else {
        //			Debug.Log ("Request to " + www.url + " succeeded");
            if (responseHandler != null)
                responseHandler(www.text);
        }
    }
            /// <summary>
            /// Get responses
            /// </summary>
            /// <param name="action">indicating the action</param>
            /// <param name="clientData">indicating the client data</param>
            /// <param name="resetToBegin">indicating the get response position</param>
            /// <param name="count">indicating the count</param>
            /// <param name="clientId">indicating the client id</param>
            void IResponseService.GetResponses(string action, string clientData, GetResponsePosition resetToBegin, int count, string clientId)
            {
                lock (this.lockObjectToProtectHandlers)
                {
                    if (this.handlers == null)
                    {
                        throw new ObjectDisposedException("WebBrokerFrontendForGetResponse");
                    }

                    HttpWebRequest     request = SOAWebServiceRequestBuilder.GenerateGetResponseWebRequest(this.brokerNode, this.sessionId, clientId, this.credential, action, clientData, count, resetToBegin == GetResponsePosition.Begin);
                    WebResponseHandler handler = new WebResponseHandler(request, clientData, this.callback);
                    this.handlers.Add(handler);
                    handler.Completed += new EventHandler(Handler_Completed);
                }
            }
예제 #5
0
    IEnumerator PostFormRequest(string url, WebResponseHandler <string> onResponse)
    {
        WWWForm form = new WWWForm();

        form.AddField("username", "Test001");
        form.AddField("name", "Tester 001");
        form.AddField("action", "PostRequest");

        var req = UWebRequest.UWebRequestCreator.PostRequest(url, form, new DownloadHandlerBuffer());        //UnityWebRequest.Post(url, form);

        yield return(req.Send());

        var strResponse = req.downloadHandler.text;
        var response    = new UWebResponse <string>(url, req.responseCode, req.error, strResponse);

        Debug.LogFormat("Web request {0} succes.\nResponse: {1}", url, strResponse);
        onResponse(response);
    }
예제 #6
0
 public static Coroutine request( string url, byte[] data, Dictionary<string, string> headers, WebResponseHandler callback, WebErrorHandler errorHandler)
 {
     return Scheduler.startCoroutine(worker( new WWW(url, data, headers), callback, errorHandler));
 }
예제 #7
0
 public static Coroutine request( string url, byte[] data, Dictionary<string, string> headers, WebResponseHandler callback)
 {
     return request(url, data, headers, callback, null);
 }
예제 #8
0
 public static Coroutine request(string url, byte[] data, Hashtable headers, WebResponseHandler callback, WebErrorHandler errorHandler)
 {
     return(Scheduler.startCoroutine(worker(new WWW(url, data, headers), callback, errorHandler)));
 }
예제 #9
0
 public static Coroutine request(string url, byte[] data, Hashtable headers, WebResponseHandler callback)
 {
     return(request(url, data, headers, callback, null));
 }
예제 #10
0
 public static Coroutine request(string url, byte[] data, Dictionary <string, string> headers, WebResponseHandler callback)
 {
     return(request(url, data, headers, callback, null));
 }
예제 #11
0
 public static Coroutine request( string url, byte[] data, Hashtable headers, WebResponseHandler callback)
 {
     return request(url, data, headers, callback, null);
 }