I am trying to post data from a Textarea to a classic ASP script that updates the MS SQL on the local machine then posts to a PHP script on another server. However doing the below does not work, as it will cut off the data for the textarea. It has special characters in it for HTML and other data.
So my question is, how do I pass this data through a POST using ASP Classic?
I have been searching all day, so hopefully someone can enlighten me, thanks!
strUrl = "http://www.example.com/index.php"
requestData = request("request")
requestData2 = request("request2")
strData = "request=" & requestData & "&request2=" & requestData2
postHTML (strUrl, strData)
function postHTML (strUrl, strData)
Set xmlHttp = Server.Createobject("MSXML2.ServerXMLHTTP")
xmlHttp.Open "POST", strUrl, False
xmlHttp.setRequestHeader "User-Agent", "asp httprequest"
xmlHttp.setRequestHeader "content-type", "application/x-www-form-urlencoded"
xmlHttp.Send strData
postHTML = xmlHttp.responseText
xmlHttp.abort()
set xmlHttp = Nothing
end function
For example if an & is in the requestdata2, anything after that & is truncated, because it is thinking it is starting a new string. But I want to be able to pass this along.
Only Solution I can think of as of right now: do a string replace for special characters such as = and & and restore them with another string replace on the php server. This however is not what I want to accomplish this task. I would like the correct way of sending a post.
You need to URL encode the parameter values, so change this line...
strData = "request=" & requestData & "&request2=" & requestData2
...to...
strData = "request=" & Server.UrlEncode(requestData) & "&request2=" & Server.UrlEncode(requestData2)
The receiving server should automatically decode the values.
Related
I use Rest Assured framework (Java).
I need to send integer array as http-param in get request: http://example.com:8080/myservice?data_ids=11,22,33
Integer[] ids = new Integer[] {11, 22, 33};
...
RequestSpecificationImpl request = (RequestSpecificationImpl)RestAssured.given();
request.baseUri("http://example.com");
request.port(8080);
request.basePath("/myservice");
...
String ids_as_string = Arrays.toString(ids).replaceAll("\\s|[\\[]|[]]", "");
request.params("data_ids", ids_as_string);
System.out.println("Params: " + request.getRequestParams().toString());
System.out.println("URI" + request.getURI());
What I see in the console:
Params: {data_ids=11,22,33}
URI: http://example.com:8080/myservice?data_ids=11%2C22%2C33
Why do my commas transform into '%2C'?
What needs to be done to ensure that commas are passed as they should?
Disable URL encoding, simple as that
given().urlEncodingEnabled(false);
Official documentation
Verified locally,
I have XULrunner opening a browser window that loads a XUL page from my local server. I am trying to post some data back to my PHP but with little success. I am just using the example at https://developer.mozilla.org/en-US/Add-ons/Code_snippets/Post_data_to_window
Here's what my javascript looks like
var params = obj.getAttribute('params');
var url = obj.getAttribute('url');
alert(params + ' - ' + url);
const Cc = Components.classes;
const Ci = Components.interfaces;
var stringStream = Cc['#mozilla.org/io/string-input-stream;1'].createInstance(Ci.nsIStringInputStream);
stringStream.data = params;
var postdata = Cc['#mozilla.org/network/mime-input-stream;1'].createInstance(Ci.nsIMIMEInputStream);
postdata.addHeader('Content-Type', 'application/x-www-form-urlencoded');
postdata.addContentLength = true;
postdata.setData(stringStream);
document.getElementById('mainbrowser').loadURI(url, null, postdata, null);
Without trying to confuse the matter too much, this is obviously part of a much bigger picture. The only part not shown, that is relevant, is where obj is derived. Basically it is a temporary XUL element that has all the parameters stored in it for easy access as I pass them around to different functions in my javascript. Also the params is in the format of name1=data1&name2=data2.
I know it is working up to the alert as it does outputs the parameters that I am sending. I am also sure the browser is being reloaded as the data I entered in the form is being cleared each time I submit it. But in my PHP if I output the contents of $_POST there is nothing.
I did have this working using XMLHttpRequest but it wasn't ideal for how I needed things to work. So I am hoping to get his method working.
Below I have this code:
string _strTemplate = _strDownloadTemplate + IDReq + "/" + _strFileName;
Uri url = new Uri(_strTemplate);
As you can see, I'm converting the strTemplate (which carries the link of a page that I need to sent by email for the user) to a URL Format. My email body has several fields that I'm replacing with the correct value:
strMailMessage = strMailMessage.Replace("_LinkTemplate", url);
I'm getting an error because the method string.Replace takes strings as parameters only.
Is there a way to get around this?
I was thinking about pass the URL value through my page (page.aspx) but if there's a way to do so through this method, it would be better for me.
Thanks!
Assuming this is C# and .NET, yes, String.Replace() works with strings.
Did you try:
strMailMessage = strMailMessage.Replace("_LinkTemplate", url.ToString());
I need to develop a small Rails app that makes a request to an JSON API, introducing the parameters into an initial form, check if we get a real response and then render the results into a view (html.erb).
Do you know where can I get good material to do these steps? Any help is welcome.
I'm reading some near example:
params_string = "whatever"
params_string_with_api_key = params_string + "&" + ##API_KEY
hashkey = Digest::SHA1.hexdigest(params_string_with_api_key)
params_string += "&hashkey=#{hashkey}"
res = Net::HTTP.get_response("api.somecompany.com", "/some/url.json?#{params_string}")
res_sha1 = Digest::SHA1.hexdigest(res.body + ##API_KEY)
#verified = res["X-Somecompany-Response-Signature"] == res_sha1
parsed_json = ActiveSupport::JSON.decode(res.body)
#results = parsed_json["results"]
Is it always needed to encode the parameters string when you do the Net::HTPP request? Is there another way?
What does exactly params_string += "&hashkey=#{hashkey}"?
Thank you!
What does exactly params_string += "&hashkey=#{hashkey}"?
params_string is a string that looks like ?param1=val¶m2=val2.... Your last piece of code is just appending another param to the string. If your issue is with the #{} fragment, this syntax, in a ruby double-quoted string, allows you to use the value of a var.
Is it always needed to encode the parameters string when you do the Net::HTPP request? Is there another way?
I don't see the parameters string being encoded here. All I see is a checking of the results, done by comparing a response header with a SHA1'd response body.
Not really related to your questions : I went away from Net::HTTP a while back, having troubles with segfault. I now use Typhoeus for all requests through the network.
I am trying to gather data on specific events from a company website: http://pipeline.kindermorgan.com/infoposting/notices.aspx?type=CRIT
I have worked a lot of similar websites but so far they have been pretty simple and it’s just a matter of going to the website and working with the response stream. In this case the website requires you to select a value from the first combo box (TSP/TSP Name). Without any info being passed, the URL will return the data associated with the first item in the list. I really need to be able to get the data associated with any of the items in the list.
Here is the code I have been using thus far but it fails with a Server Error 500 so I am guessing that either I did not form the POST properly or am missing some data in the post data):
For the page I have listed above I just want to get a response stream with the table of the notices for a particular TSP from the combo box (starting with Trailblazer). I know the control is “ctl00$ContentPlaceHolder1$ddlpipeline” and the value I want to send is 24. When I navigate via IE, I also have to press the “Retrieve” button.
When I look at the POST request using FireBug, I notice that there are a lot of other target/values included. I’m not sure if I need to send all of those as well and (having never done a POST before) I am not sure how to format the data in the POST to do that.
Bear with me if this request seems odd. I am more of a database person and am looking to automate a lot of the stuff we are required to look at manually every day. Any help would be greatly appreciated!
var encoding = new ASCIIEncoding();
var postData = "ctl00$ContentPlaceHolder1$ddlpipeline=24";
byte[] data = encoding.GetBytes(postData);
string RemoteURI = "http://pipeline.kindermorgan.com/infoposting/notices.aspx?type=CRIT";
var myRequest = (HttpWebRequest)WebRequest.Create(RemoteURI);
myRequest.Method = "POST";
myRequest.ContentType = "application/x-www-form-urlencoded";
myRequest.ContentLength = data.Length;
var newStream = myRequest.GetRequestStream();
newStream.Write(data, 0, data.Length);
newStream.Close();
var response = myRequest.GetResponse();
var responseStream = response.GetResponseStream();
var responseReader = new StreamReader(responseStream);
I actually resolved the issue and there were a number of things I found out in the process that I will share for the benefit of others who may look at this thread.
First, I had to build the POST data exactly as it appears in the POST in a browser (I used Firebug to see the POST data). This meant getting the hidden arguments as well (particularly VIEWSTATE and EVENTVALIDATION). I was able to get these by just downloading the default page source for the page (by the way, i do this in the code because it is not static for this site) and parsing out the values for the hidden fields. I then build the POST data string with any changes I may have (in my case changing the date was important but in the future I may change other things).
Now the thing that really had me stumped. I confirmed that the POST data string was exactly the same as the one sent by FireFox/FireBug through a character by character comparison and it still wouldn't work. I then remembered in a previous scraping case that I had to set the user agent.
So here is the code I ended up with:
string postData = String.Format("__EVENTTARGET=&__EVENTARGUMENT=&__LASTFOCUS="
+ "&__VIEWSTATE={0}"
+ "&ctl00%24UltraWebTree1={1}"
+ "&ctl00%24ContentPlaceHolder1%24ddlNoticeCategory={2}"
+ "&ctl00%24ContentPlaceHolder1%24ddlpipeline={3}"
+ "&ctl00%24ContentPlaceHolder1%24Button1={4}"
+ "&ctl00%24ContentPlaceHolder1%24tbDate={5}"
+ "&ctl00%24ContentPlaceHolder1%24ddlNoticeType={6}"
+ "&ctl00%24ContentPlaceHolder1%24tbSubject={7}"
+ "&ctl00%24ContentPlaceHolder1%24ddlNoticeSubType={8}"
+ "&ctl00%24ContentPlaceHolder1%24ddlOrderBy={9}"
+ "&ctl00%24ContentPlaceHolder1%24hfmode={10}"
+ "&ctl00%24ContentPlaceHolder1%24hfODSCommand={11}&ctl00%24hfPipeline={12}"
+ "&__PREVIOUSPAGE={13}&__EVENTVALIDATION={14}",
viewstate, webtree, noticecategory, pplcode,
button1, todaydate, noticetype, subject,
noticesubtype, orderby, hfmode, hfODSCommand,
hfPipeline, previouspage, eventvalidation);
var encoding = new ASCIIEncoding();
byte[] data = encoding.GetBytes(postData);
var myRequest = (HttpWebRequest)WebRequest.Create(RemoteURI);
myRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)" ;
myRequest.Method = "POST" ;
myRequest.ContentType = "application/x-www-form-urlencoded";
myRequest.ContentLength = data.Length;
var newStream = myRequest.GetRequestStream();
newStream.Write(data, 0, data.Length);
newStream.Close();
var myresponse = myRequest.GetResponse();
var responseStream = myresponse.GetResponseStream();
var responseReader = new StreamReader(responseStream);
string webpagesource = responseReader.ReadToEnd();
Hope this helps someone else.