Ok so I'm trying to create a CLR to do an HTTP Post for a REST API. The GET and DELETE methods (which are not included below) work great. The problem is with the post and necessary parameters. I've googled till the cows have come home and still no joy.
Below I have the url hardcoded just to know what I'm passing in. I continuously get 'The remote server returned an error: (400) Bad Request.' returned. If I do this through a form it works. Just not through the CLR so clearly I'm doing something wrong.
One thing that I did notice is that although I'm hardcoding the url as an encoded string, when it is actually sent via request.GetResponse(), it is not encoded. I'm not sure how it is getting unencoded? If I could just get it to send in the correct format I think that it would work. Any thoughts here?
public static void AFWSPost2(SqlString weburl, SqlString token, out SqlString returnval)
string url = Convert.ToString(weburl);
string feedData = string.Empty;
HttpWebRequest request = null;
HttpWebResponse response = null;
Stream stream = null;
StreamReader streamReader = null;
request = (HttpWebRequest)WebRequest.Create("https://restapi.software.com/api/1/logo?imagelink=http%3A%2F%2Fwww.website.org%2FPortals%2F_default%2FSkins%2F2015%2Fimages%2Flogo-full.png&name=OurLogo");
request.Method = "POST";
request.Headers.Add("Authorization", "Bearer " + token.ToString());
request.ContentType = "multipart/form-data";
response = (HttpWebResponse)request.GetResponse();
stream = response.GetResponseStream();
streamReader = new StreamReader(stream);
feedData = streamReader.ReadToEnd();
catch (Exception ex)
if (response != null && stream != null && streamReader != null)
returnval = feedData;