I have an application on windows mobile platform cf3.5. This communicates with a web server and they do it nicely, requests get correct replies. However, on every request it throws a System.UriFormatException in visual studio output window. Uris look like this:
http://api/Information/TagKey/4952b9ff-af55-4219-95b8-1ac57a70b7a8/L0011421
How can I know what is wrong with these uris? Should I change '-' chars in the guid fields or what?
I build the uri by this method, where uri is the base address of the server and dictionary contains the parameters:
private static string buildUri(string uri, Dictionary<string, string> data)
{
StringBuilder _uri = new StringBuilder(uri);
foreach(KeyValuePair<string, string> item in data)
{
_uri.Append("/" + item.Value);
}
return _uri.ToString();
}
This is used by this createRequest method:
private static HttpWebRequest createRequest(string uri, HttpMethods method, Dictionary<string, string> data, Dictionary<string, object> postdata)
{
string fullUri = buildUri(uri, data);
Classes.Log.Write("/// "+fullUri);
WebRequest request = HttpWebRequest.Create(fullUri);
request.Method = Enum.ToObject(typeof(HttpMethods), method).ToString();
request.ContentType = "application/json; charset=utf-8";
((HttpWebRequest)request).Accept = "application/json; charset=utf-8";
request.ContentLength = 0;
if (method != HttpMethods.GET && method != HttpMethods.DELETE && postdata != null)
{
Encoding encoding = Encoding.UTF8;
string postData = buildPostData(postdata, "application/json");
byte[] byteArray = encoding.GetBytes(postData);
request.ContentLength = byteArray.Length;
if (byteArray != null && byteArray.Length > 0)
{
using (Stream stream = request.GetRequestStream())
{
stream.Write(byteArray, 0, (int)request.ContentLength);
}
}
}
return (HttpWebRequest)request;
}
It throws the exception at
WebResponse response = request.GetResponse();
that is in an other method.
I have generated an Uri object first by the string and it doesn't throw any exceptions.