I need to send the follow querystring:
http://prod.intranet.siemens.com.br/drvs/index.aspx?page=2&pag=4&varpatch=%20C:\Documents%20and%20Settings\OPE253\My%20Documents\Ca$##!
Then i try to assing this to a string,but .NET break string at
http://prod.intranet.siemens.com.br/drvs/index.aspx?page=2&pag=4&varpatch=%20C:\Documents%20and%20Settings\OPE253\My%20Documents\Ca$#
'#" do not appears in querystring
Any ideas?
No, because "#" is a reserved character. It's used to link to a specific location in a web page:
http://en.wikipedia.org/wiki/HTML_anchor#Overview
So browsers split the URL at the "#".
You'll need to encode the "#" as "%23"
You need to use String.Replace:
Dim outputURL As String = inputURL.Replace("#", "%23")
or HttpUtility.UrlEncode (only encode the querystring):
Dim outputQueryString As String = HttpUtility.UrlEncode(inputQueryString)
Related
I want to know how to append link in current URL. For eg: me link is https://www.google.co.in/ in current program now I have to append /#q=ask+questions in this URL.
Please help.
I know how to get current url(by using getCurrentUrl() syntax)
Thanks
You could use URIBuilder. Something like this:
String someUrl = "https://www.google.co.in";
// or perhaps
// String someUrl = browser.getCurrentUrl();
URIBuilder uri = new URIBuilder(someUrl);
uri.setPath("search");
uri.addQueryParam("q", "ask+questions");
Assert.assertEquals(uri.toString(), "https://www.google.co.in/search?q=ask%2Bquestions");
// or perhaps
// browser.get(uri.toString());
getCurrentUrlUrl() has a return type of String. So you can save it's value and play around like you can with any String.
Take an example, I want to get this url and then append your string and then get() this new webpage:
String url = driver.getCurrentUrl();
String newurl = url+"/#q=ask+questions";
driver.get(newurl);
I'm using the command IO.File.AppendAllLines("3.txt", "text", System.Text.Encoding.Default)
to write to 3.txt.
But the string is writing in down.
How I can write a string upper?
Call the strings ToUpper method to make the string upper case
IO.File.AppendAllLines("3.txt", "text".ToUpper(), System.Text.Encoding.Default)
The .Append() method will always append(add) the given string to an existing content. so n this case you cannot do like this.
I suggest you to read the content first, write the content back to the file along with the additional string. If you are expecting this, then the following code will help you:
var currentContent= File.ReadAllText(#"D:\3.txt");
File.WriteAllText(#"D:\3.txt", "Some string" + currentContent);
// here you are adding "Some string" at the begining of the file
this is the JSON string the data is required in to be sent using a given URL.
$jsonstr = '{"data":
[{
"id":"5",
"owner_id":"0",
"status":"unassigned",
"first_name":"Test",
"last_name":"IS",
"tobacco_user":"",
"date_of_birth":"",
"age":"",
"gender":"",
"email":"lb#you.com",
"zip":"",
"phone":"(210)629-2560",
"phone_type":"cell",
"phone_alt":"",
"phone_alt_type":"",
"product_msip":"",
"product_pdp":"",
"product_sdhv":""
},
I am using VB.net and i need to create this string using VB.net. I tried using namevaluecollection and doing a POST. I also tried making a string and send data using GET. Both failed. how can i do this?
Create an object with property names that are identical to those in your example, use the DataContract and DataMember attributes to mark serialization.
Then use the JavaScriptSerializer to serialize the object into JSON.
you can use the class when you want to work with JavaScript Object Notation (JSON) in managed code.
If you don't want to build an actual class as #Oded recommended you can just hack it together as a string. I usually use a NameValueCollection as you said you tried.
''//Setup some values
Dim NVC As New NameValueCollection()
NVC.Add("id", "5")
NVC.Add("owner_id", "0")
NVC.Add("status", "unassigned")
''//Convert to string
Dim Pairs As New List(Of String)
For Each N As String In NVC.Keys
Pairs.Add(String.Format("""{0}"":""{1}""", N.Replace("""", "\"""), NVC(N).Replace("""", "\""")))
Next
Dim S = Join(Pairs.ToArray(), ",")
S now holds "id":"5","owner_id":"0","status":"unassigned" which you should be able to concat into your bigger JSON string.
I have a cookie saved to the user as follows...
Dim searchCookie As HttpCookie = New HttpCookie("SearchCriteria")
searchCookie.Item("SearchText") = FullSearchCriteria.SearchText
searchCookie.Item("SearchType") = FullSearchCriteria.SearchType
The SearchText stores a value they have input in a previous page. We have observed if there is an ampersand in the cookie (eg Tyne & Wear), then the cookie doesn't save subsequent values (SearchType).
What happens is the cookie is output like this:
SearchText=Tyne &
Obviously the ampersand is confusing the cookie. Is there a way to prevent this happening?
You can use the URLEncode method.
Something like:
imports HttpContext.Current
...
Dim searchCookie As HttpCookie = New HttpCookie("SearchCriteria")
searchCookie.Item("SearchText") = Server.UrlEncode(FullSearchCriteria.SearchText)
searchCookie.Item("SearchType") = Server.UrlEncode(FullSearchCriteria.SearchType)
This is essential as only certain characters are allowed in cookies with characters such as ampersands breaking them.
D'oh! I'm such a dork...
Dim searchCookie As HttpCookie = New HttpCookie("SearchCriteria")
searchCookie.Item("SearchText") = HttpContext.Current.Server.UrlEncode(FullSearchCriteria.SearchText)
searchCookie.Item("SearchType") = HttpContext.Current.Server.UrlEncode(FullSearchCriteria.SearchType)
The cookie values need to be encoded. I'm no VB expert, but it looks like this is done with the method
System.Web.HttpUtility.UrlEncode
We have implmented a REST-style get service Using WCF in .Net 3.5. This service retrieves research documents. The string 'synopsis' indicated in the code bolow contains non-english characteres which the browser deliveres as "????????".
private void ReturnSynopsisInfo(IApiWebOperationContext context, OutgoingWebResponseContext outgoingResp, string synopsis)
{
SetResponseHeaders(outgoingResp, HttpStatusCode.OK);
outgoingResp.ContentType = "text/html; charset=UTF-8";
context.Result = new MemoryStream(Encoding.ASCII.GetBytes(synopsis));
}
Any advise is much appreciated.
Thank You.
It seems you are declaring the encoding as utf-8 in the content-type header, but actually using ASCII encoding in stream. The ASCII encoder will silently change any non-ascii character into a question mark.
You probably want to use UTF8Encoding rater than ASCIIEncoding.