Url Params not accepting lengthy strings - c#

While sending the image to Web server along with data it is not accepting the lengthy strings. I am sending the data through url. its working good with smaller strings for country,continent and city
http://user.co/UserImage.svc/InsertObjectImage?UserId={UserId}&CategoryId={CategoryId}&ImageName={ImageName}&Gender={Gender}&Continent={Continent}&Country={Country}&City={City}
The above url am using in program upto "?", after that it is with params
NSString *url=[NSString stringWithFormat:#"http://userdata.co.in/UserImage.svc/InsertFacialImage?%#",requestString];
NSLog(#"insert facial image url : %#",url);
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init] ;
[request setURL:[NSURL URLWithString:url]];
[request setHTTPMethod:#"POST"];
The code I am using to send the image along with data.Here am passing strings with url.Objective-C NSString can hold the data up to 4.2Billion characters. In the web server the I made it to allow 200 characters for param. But when I am sending the lengthy string like united states of america its making the trouble not storing the data.Services developed in WCF using C#

There are length limitations to URLs but it is also worth checking that your URL is valid.
URLs need to be correctly encoded so you should be passing united%20states%20of%20america in your URL string rather than united states of america.
This is because URL encodes spaces to %20. For any other "special" characters these are also encoded. There are many online resource that should help you and a quick online encoder / decoder can be found here: http://meyerweb.com/eric/tools/dencoder/

Related

Uri %20 converter problem when trying to build a HttpRequestMessage - C#

I'm trying to build a http request using HttpRequestMessage from .net. The problem is that my URL contains %20 in parameters, and I need to send specifically %20 not space caracter. But to use HttpRequestMessage I have to transform my string URL in URI, and then it converts the %20 in space.
I tried a few changes, using encoders before sending to httpRequestMessage. The strange part is that if I encode a "%" for example, it maintain the %25 value, but for spaces does't not.
Example of me testing Uri.ScapeDataString(), look how it keeps the correctly encoding from '['character, but it looses 'space' caracter:
Example with ScapeDataString
For me this is clearly a problem on Uri conversion.

Sending query parameters using C#

I want to send a string to a web API using GET. My string contains a few characters that are not accepted in URL or need to be escaped. How can I scape them and send them to the server?
If it helps, my server is written in PHP so any encoding needs to be reversed in PHP.
If your data has HTTP Wildcards in it try to serialize or encode it that outputs a string doesn't contain any HTTP Wildcards.You can pass data with uriencode or some other encoding algorithm like for example (base64) :
string byteArray = System.Encoding.UTF8.GetBytes(yourData);
string encoded = Convert.ToBase64String(byteArray);
string exampleUri="a.com/b.php?data="+encoded;
Decode it in PHP like this :
$data = base64_decode($_GET["data"]);
As i said you can also use uriencoding with :
HttpUtility.UrlEncode / UrlDecode (You need System.Web assembly in your project)

how to send Image bytes using query string

I am new in developing Rest service using web api in asp .net .
I try to send image byte with in the query string.but i could not abe to send image byte with in query string.
I have Basic concept in GET And Post.
Post don't have any limitation to send data.
Herewith i have added my sample code also.
[AcceptVerbs("GET", "POST")]
public string PostRoute(string routingRequestTemplate)
{
return routingRequestTemplate;
}
My string value:
hjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjsgbYwjolIo2s2YoqTF4YeSWSmTLmm1UNwuk/W4340Jm2jmTwLsRptpFkMNmgcKaZtZse1SAoSdfm9u0MpAMXgj5ZWHk3KqEs4qRrQQYcjfpyFab3HSqajJ4DCwIXu7NCBwV9SrAUKRr8DR4poJ3M0zFo6m9EUF+uA5uFdlKG7w9118kehITj2k1N+m8kJl2riTFI3iO8gjOUfHyQrVw32E3Mg+yW0pF3AuJ6L2sV7s5vHzu19066VN9I/DyBTwqXl45u1QaolyD0Ufw7OFcK+A4KT6C5mP7v5ew+dTYh1CeB/i5Vr5P5MEYvApkC3jM5UmzgJ+lM7uYGj+VztNO4Khyl3qG8OPQOH4dncAPXP95ka/lfflcrIAKujLNxH0p3/ej4Ekur4bNAq3dXGtr/bs8wI2K3FS6r3pHUHp/Gp3PXmD89QImF5Yw/s8iup6+4PsP8TU/F/gCX8pFzMTvkQweg4pQhQou8iSXxwXenuZOy7fB+wmdt30AFxhERSanMbf2Blu7u9jbA8eeGtt8Pbu6htDENE3tEPwyeTa4IU1xK04CT0ytrDhzsktFIltVOsvEOyuF7yxuhIt+rJsqdm38AR4sLmNnl8QZ/Nva2cX4/CJ+H5lUvp+Hptcubkha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fBs+wBrIHH4TKleA3wEDxvDXN5XFlAJq6oyS3x6Nb/rwOwdxlIC3gcAtLgadWzpHqpg0
url:
http://localhost:64528/api/controller/PostRoute?routingRequestTemplate=string
following error I got
Request filtering is configured on the Web server to deny the request because the query string is too long.
Querystring have limition of size, below is details
Maximum length of Querystring is based on the browser not depend upon the asp.net.
Maximum length of a querystring in IE 4.0 and above is ~2048 characters
IE. 4,5,6,7, - 2,048 characters.
Opera supports - 4050 characters.
Netscape 6 supports - 2000 characters.
Firefox Supports - 6000 characters
Try below codes with Post verb :
[HttpPost]
public ActionResult PostRoute(HttpPostedFileBase file) {
}
this link will also help you :
Uploading image in ASP.NET MVC
What is the maximum possible length of a query string?
Your image will need to be quite small, and base64 encoded, or made url safe. URL length is quite limited. I would suggest putting it in a POST body.
http://en.wikipedia.org/wiki/Base64

Encode header value using WebClient.Headers.Add()

I am using HTTP headers to send a string which contains Unicode characters (such as ñ) to a custom http server.
When I add the string as a header:
webClient.Headers.Add("Custom-Data", "señor");
It is interpreted by the server as:
se�or
Obviously I need to encode the value differently, but I am unsure what encoding to use.
How should I encode this HTTP header to preserve extended/special characters?
porneL's answer to a related question is confusing.
Unanswered, related: C# WebClient non-english request header value encoding
As #Jordan suggested, representing the string as base64 (with UTF8 encoding) worked well:
On the client side:
webClient.Headers.Add("Custom-Data",
Convert.ToBase64String(Encoding.UTF8.GetBytes("señor")));
And on the server:
string customData = Encoding.UTF8.GetString(Convert.FromBase64String(customHeader.Value));

How to Post values from iPhone using ASIHttp?

I want to send some values from my iPhone application to an ASp.Net web page in server. I am using asihttp for that. Its processing the request and invoking the page on server. But the none of the values are retrieved in server side. Below is the code from iPhone app.
NSURL *url = [NSURL URLWithString:urlString];
ASIFormDataRequest *request = [[[ASIFormDataRequest alloc] initWithURL:url] autorelease];
[request setPostValue:#"abc" forKey:#"from"];
[request setPostValue:#"abc" forKey:#"name"];
[request setPostValue:#"abc" forKey:#"phone"];
[request setDelegate:self];
[request startSynchronous];
On Server side I am using asp.net c#. THis is the code using for retriving values. But I am getting emtpy string?
sendMail(Request.QueryString["name"],Request.QueryString["from"],Request.QueryString["phone"]);
Could Someone help Please?
I don't think Request.QueryString["name"] will retrieve a post parameter. You either need to change your ASIHttpRequest to include the parameters in the query string, or modify your ASP.NET code to expect post parameters.
You could try Request.Form["name"], Request.Form["phone"], etc. on the server side.
Or, you could try:
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:#"%#?name=%#&...",urlString,name,...];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
on the client side.
QueryString is for values in the URL. A post will have values in Request.Form or just Request which will search through QueryString & Form for the values.
Another question with more detail about QueryString vs Form.
Request["key"] vs Request.Params["key"] vs Request.QueryString["key"]

Categories

Resources