CompareCloudware.SocialNetworking/LinkedIn/oAuthLinkedIn.cs
/// <summary>
/// Submit a web request using oAuth.
/// </summary>
/// <param name="method">GET or POST</param>
/// <param name="url">The full url, including the querystring.</param>
/// <param name="postData">Data to post (querystring format)</param>
/// <returns>The web server response.</returns>
Submit a web request using oAuth.
Submit a web request using oAuth .
public string oAuthWebRequest(Method method, string url, string postData)
        {
            string outUrl = "";
            string querystring = "";
            string ret = "";
            if (method == Method.POST)
            {
                if (postData.Length > 0)
                {
                    NameValueCollection qs = HttpUtility.ParseQueryString(postData);
                    postData = "";
                    foreach (string key in qs.AllKeys)
                    {
                        if (postData.Length > 0)
                        {
                            postData += "&";
                        }
                        qs[key] = HttpUtility.UrlDecode(qs[key]);
                        qs[key] = this.UrlEncode(qs[key]);
                        postData += key + "=" + qs[key];
                    }
                    if (url.IndexOf("?") > 0)
                    {
                        url += "&";
                    }
                    else
                    {
                        url += "?";
                    }
                    url += postData;
                }
            }
            Uri uri = new Uri(url);
            string nonce = this.GenerateNonce();
            string timeStamp = this.GenerateTimeStamp();
            string callback = "";
            if (url.ToString().Contains(REQUEST_TOKEN))
                callback = CALLBACK;
            string sig = this.GenerateSignature(uri,
                this.ConsumerKey,
                this.ConsumerSecret,
                this.Token,
                this.TokenSecret,
                method.ToString(),
                timeStamp,
                nonce,
                callback,
                out outUrl,
                out querystring);
            querystring += "&oauth_signature=" + HttpUtility.UrlEncode(sig);
            if (method == Method.POST)
            {
                postData = querystring;
                querystring = "";
            }
            if (querystring.Length > 0)
            {
                outUrl += "?";
            }
            if (method == Method.POST || method == Method.GET)
                ret = WebRequest(method, outUrl + querystring, postData);
            return ret;
        }
public string oAuthWebRequest ( Method method , string url , string postData ) { string outUrl = " " ; string querystring = " " ; string ret = " " ; if ( method == Method . POST ) { if ( postData . Length > 0 ) { NameValueCollection qs = HttpUtility . ParseQueryString ( postData ) ; postData = " " ; foreach ( string key in qs . AllKeys ) { if ( postData . Length > 0 ) { postData += " " ; } qs [ key ] = HttpUtility . UrlDecode ( qs [ key ] ) ; qs [ key ] = this . UrlEncode ( qs [ key ] ) ; postData += key + " " + qs [ key ] ; } if ( url . IndexOf ( " " ) > 0 ) { url += " " ; } else { url += " " ; } url += postData ; } } Uri uri = new Uri ( url ) ; string nonce = this . GenerateNonce ( ) ; string timeStamp = this . GenerateTimeStamp ( ) ; string callback = " " ; if ( url . ToString ( ) . Contains ( REQUEST_TOKEN ) ) callback = CALLBACK ; string sig = this . GenerateSignature ( uri , this . ConsumerKey , this . ConsumerSecret , this . Token , this . TokenSecret , method . ToString ( ) , timeStamp , nonce , callback , out outUrl , out querystring ) ; querystring += " " + HttpUtility . UrlEncode ( sig ) ; if ( method == Method . POST ) { postData = querystring ; querystring = " " ; } if ( querystring . Length > 0 ) { outUrl += " " ; } if ( method == Method . POST || method == Method . GET ) ret = WebRequest ( method , outUrl + querystring , postData ) ; return ret ; }
Submit a web request using oAuth.
Submit a web request using oAuth .
//Setup postData for signing. //Add the postData to the querystring. //Decode the parameters and re-encode using the oAuth UrlEncode method. //Generate Signature //Convert the querystring to postData
The web server response.
The web server response .
method
Method
GET or POST
GET or POST
url
string
The full url, including the querystring.
The full url including the querystring .
postData
string
Data to post (querystring format)
Data to post ( querystring format )