SetHeader() public method

public SetHeader ( string name, string value ) : void
name string
value string
return void
    public IEnumerator getMaterials()
    {
        Dictionary <string, string> parameters = new Dictionary <string, string>();

        parameters.Add("user", MaterialiseKeys.EMAIL);
        HTTP.Request materialsRequest = new HTTP.Request("GET", MaterialiseUrls.MATERIALS_URL + toQueryString(parameters));
        materialsRequest.SetHeader("Accept", "application/json");
        materialsRequest.SetHeader("Content-type", "application/x-www-form-urlencoded");
        materialsRequest.Send();

        while (!materialsRequest.isDone)
        {
            yield return(new WaitForEndOfFrame());
        }

        if (materialsRequest.exception != null)
        {
            Debug.LogError(materialsRequest.exception.ToString());
        }

        else
        {
            IDictionary response = (IDictionary)MiniJSON.Json.Deserialize(materialsRequest.response.Text);
            this.materials = (IList)response["materials"];
        }
    }
    public IEnumerator getPrices(string modelReference, string materialID, string finishID, string quantity, string xDimMm, string yDimMm, string zDimMm, string volumeCm3, string surfaceCm2, string countryCode, string city, string zipCode)
    {
        Dictionary <string, object> parameters         = new Dictionary <string, object>();
        Dictionary <string, string> modelParameters    = new Dictionary <string, string>();
        Dictionary <string, string> shippingParameters = new Dictionary <string, string>();

        List <Dictionary <string, string> > modelsList = new List <Dictionary <string, string> >();

        modelParameters.Add("ModelReference", modelReference);
        modelParameters.Add("MaterialID", materialID);
        modelParameters.Add("FinishID", finishID);
        modelParameters.Add("Quantity", quantity);
        modelParameters.Add("XDimMm", xDimMm);
        modelParameters.Add("YDimMm", yDimMm);
        modelParameters.Add("ZDimMm", zDimMm);
        modelParameters.Add("VolumeCm3", volumeCm3);
        modelParameters.Add("SurfaceCm2", surfaceCm2);

        modelsList.Add(modelParameters);

        shippingParameters.Add("CountryCode", countryCode);
        shippingParameters.Add("City", city);
        shippingParameters.Add("ZipCode", zipCode);

        parameters.Add("models", modelsList);
        parameters.Add("shipmentInfo", shippingParameters);

        string data = MiniJSON.Json.Serialize(parameters);

        HTTP.Request priceRequest = new HTTP.Request("POST", MaterialiseUrls.PRICES_URL, UTF8Encoding.UTF8.GetBytes(data));
        priceRequest.SetHeader("Accept", "application/json");
        priceRequest.SetHeader("Content-type", "application/json");
        priceRequest.SetHeader("APICode", MaterialiseKeys.API_CODE);

        priceRequest.Send();

        while (!priceRequest.isDone)
        {
            yield return(new WaitForEndOfFrame());
        }

        if (priceRequest.exception != null)
        {
            Debug.LogError(priceRequest.exception.ToString());
        }

        else
        {
            prices = (IDictionary)MiniJSON.Json.Deserialize(priceRequest.response.Text);
        }
    }
    void uploadScore(string point, string token, string client, string expiry, string type, string uuid)
    {
        Hashtable data = new Hashtable();
        data.Add( "score",  point);
        HTTP.Request someRequest = new HTTP.Request( "post", "http://boiling-sea-3589.herokuapp.com/api/scores", data );

        someRequest.SetHeader("Access-Token", token);
        someRequest.SetHeader("Client", client);
        someRequest.SetHeader("Expiry", expiry);
        someRequest.SetHeader("Token-Type", type);
        someRequest.SetHeader("Uid", uuid);

        someRequest.Send( ( request ) => {
            if(request.response != null) {
                Debug.LogWarning(someRequest.isDone);
                if(someRequest.isDone){
                    if(!someRequest.response.status.Equals(401)){
                        NotificationCenter.DefaultCenter().PostNotification(this, "sendMessage", "Shared!!");
                    }else {
                        NotificationCenter.DefaultCenter().PostNotification(this, "This score was shared!");
                    }
                }

            }

        });
    }
    private IEnumerator InternalDownloadFile(string tempFilename, string url, long downloadedBytes)
    {
        request = new Request ("GET", this.url);
        request.downloadDelegate = this;

        if (downloadedBytes > 0) request.SetHeader ("Range", "bytes=" + downloadedBytes + "-");

        if (request == null) {
            this.error = "Unable to create URL " + this.url;
            this.cleanupConnectionSuccessful (false);
            yield return null;
        }

        dispatchDownloadEvent (DOWNLOAD_DID_START, this);

        //Debug.Log ("Before download");
        request.Send (this.tempFilename);
        //Debug.Log ("After download");

        while (!request.isDone) {
            yield return request;
        }

        //Debug.Log ("Request finished XXX");
        if ((request.response.status == 200) || (request.response.status == 206)) {
            //Debug.Log ("[DownloadManager] Download complete");
            if (!request.response.ForceStop) cleanupConnectionSuccessful (true);
        } else if (request.response.status != -100) {
            Debug.LogError ("Download failed " + request.response.status + " " + request.response.message);
            cleanupConnectionSuccessful (false);
        }
    }
Esempio n. 5
0
    /// <summary>
    /// updates the session on the match making server 
    /// </summary>
    private void UpdateStart()
    {
        //json encode the data.
        string requestData = JSON.Encode(BuildSession());

        request = new Request("put", masterServerURL + "/session/"+sessionID);

        request.SetHeader("Content-Type", "application/json");
        request.SetHeader("Authorization", authToken);
        request.Text =requestData;

        requestFunction = "update";
        requestRunning = true;
        try
        {

            request.Send();

        }
        catch (Exception e)
        {
            requestRunning = false;
            request = null;
            serviceUnavailable = true;
            return;

        }
    }
Esempio n. 6
0
    /// <summary>
    /// async call to delete the existing registration from the server. 
    /// </summary>
    void SendUnregisterWebRequest()
    {
        deleteRequest = new Request("delete",masterServerURL + "/session/" + sessionID);

        deleteRequest.SetHeader("Content-Type", "application/json");
        deleteRequest.SetHeader("Authorization", authToken);

        try
        {

            deleteRequest.Send();

        }
        catch (Exception e)
        {

        }
    }
Esempio n. 7
0
    /// <summary>
    ///Begins the registration http request 
    /// </summary>
    private void RegistrationStart()
    {
        if (registrationStarted)
            return;
        registrationStarted = true;

        if (!StartServer ()) {

            registrationStarted = false;
            timerEnabled = true;
            timerStart = currentTime;
            return;
        }

        //json encode the data.
        string requestData = JSON.Encode (BuildSession ());

        request = new Request("post",masterServerURL + "/session");

        request.SetHeader("Content-Type", "application/json");
        request.SetHeader("Authorization",authToken);
        request.Text = requestData;

        requestFunction = "register";
        requestRunning = true;
        try {

            request.Send();

        } catch (Exception e) {
            requestRunning = false;
            request = null;
            serviceUnavailable = true;
            return;

        }
    }
Esempio n. 8
0
    /// <summary>
    /// Called when the player is ready to find a server. 
    /// </summary>
    private void JoinStart()
    {
        if (joinStarted)
            return;

        joinStarted = true;
        if (networkDisconnected)
            return;

        //json encode the data.
        string requestData = JSON.Encode (BuildSession ());

        request = new Request("post", masterServerURL + "/match");

        request.SetHeader("Content-Type", "application/json");
        request.SetHeader("Authorization", authToken);
        request.Text = requestData;

        requestFunction = "join";
        requestRunning = true;
        try
        {

            request.Send();

        }
        catch (Exception e)
        {
            requestRunning = false;
            request = null;
            serviceUnavailable = true;
            return;

        }
    }
Esempio n. 9
0
    /// <summary>
    /// gets the authorization token from the server.
    /// </summary>
    private void AuthorizeStart()
    {
        Hashtable auth = new Hashtable ();

        auth.Add ("applicationID", applicationID);
        auth.Add ("serviceID", serviceID);

        //json encode the data.
        string requestData = JSON.Encode (auth);

        request = new Request("post", authServerURL + "/authorize");

        request.SetHeader("Content-Type", "application/json");
        request.Text =requestData;

        requestFunction = "authorize";
        requestRunning = true;
        try
        {

            request.Send();

        }
        catch (Exception e)
        {
            requestRunning = false;
            request = null;
            serviceUnavailable = true;

            return;

        }
    }