Form post asp classic xmlhttp - forms

I'm trying to do a form post from another site that is not mine, but
I am not able ta give error.
There on the site the post is mounted like this:
Veja o resultado da enquete anterior ยป
<br /><br />
<form name="result" action="http://enquete.terra.com.br/enquete.cgi" method="post">
<input type="hidden" name="id_enquete" value="144143">
<input type="hidden" name="opcao" value="0">
</form>
And I'm riding in the asp script to make this post as:
<%
Dim objHttp
Dim str
str = "id_enquete=144143&opcao=0"
Set objHttp = Server.CreateObject("Msxml2.ServerXMLHTTP")
objHttp.Open "POST", "http://enquete.terra.com.br/enquete.cgi", false
objHttp.setRequestHeader "Host", "http://enquete.terra.com.br"
objHttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded; charset=iso-8859-1"
objHttp.setRequestHeader "Content-Length", Len(str)
objHttp.Send str
Response.Write(objHttp.ResponseText)
Set objHttp = nothing
%>
But not this working, does anyone know how or know where I am
wrong??
Thanks

You can't make cross domain request using AJAX due to the same origin policy. If the other site supports JSONP, you can use a script request to access the site and get data from it, of course, your parameters need to be in the URL for that to work.
<script type="text/javascript">
function resultCallback( data ) {
// do something with the returned JSON data
}
</script>
<script type="text/javascript" src="http://enquete.terra.com.br/enquete.cgi?id_enquete=144143&opacao=0&callback=resultCallback">
</script>

Code looks true; the reason why you get "Internal Server Error" is because your IIS settings for error is not in the debug mode.
You should change your IIS settings to "Send error messages to Browser" then you can see the actual error message on the browser; which is probably caused by version of the Msxml2.ServerXMLHTTP object.

Related

Why url is set in $_GET when i use post method

have you guys any ideas why the url is set in the $_GET, when i submit a form with post method?
I have a form like this:
<form action="/test/show/" method="post" enctype="multipart/form-data">
<input name="product" value="testing">
<input type="file" name="image">
<input type="submit" value="go" name="submit">
</form>
In my chrome i can see it will be send as post, but if i do this:
if (count($_GET) > 0) {
var_dump($_GET);
}
I get this result:
array(1) { ["url"]=> string(10) "test/show/" }
and i have no idea why?
Can you help me?
Under normal circumstances, with that URL, it wouldn't be. Presumably you are using mod_rewrite or similar to map /test/show onto something like /index.php?url="%2Ftest%2Fshow.
This is because PHP picked poor names for the $_GET superglobals.
An HTML form with method="GET" will put the data from its form controls in the query string, but that isn't the only way to request a URL with a query string.
$_GET contains data from the query string irrespective of the request method.

REST not working on ColdFusion

I feel like I must be missing something obvious because the REST documentation seems so simple and the code I produced appears to work correctly unless I try to access it via REST.
hello.cfc:
component rest="true" restpath="restTest"{
remote string function sayHello() httpMethod="get"{
return "Hello World";
}
}
Service Mapping:
I have tried both default yes and no with no change.
Test Page:
<html>
<head>
<title>REST Test</title>
</head>
<body>
Calling service as an object:<br>
<cfset restTest = new hello() />
<cfdump var="#restTest.sayHello()#" />
<br>
Calling service via http:<br>
<cfhttp url="http://localhost/rest/restTest" result="restResult" method="GET" />
<cfdump var="#restResult#" />
</body>
</html>
Results:
Did you try accessing without directing the call through a connector/webserver?
Keep your project inside /cfusion/wwwroot/ and then try accessing it via browser
http://localhost:8500/rest/restTest
Sample test also worked for me after changing the URL
enter image description here
It seems like you are using a wrong URL when making HTTP request to the REST service. The URL should be like this:
http://{domain}/rest/{service mapping name}/{component level rest path}/{function level restpath}
So in your case the correct URL should be:
http://localhost/rest/api/restTest
For more info read this http://www.adobe.com/devnet/coldfusion/articles/restful-web-services.html

How to pass the exact search result into a new URL

So I'm using a form in a specific page and I want to pass the exact search query to another url after submission
Example: I search for vehicles and I need the result to be domain.com/search/vehicles
So this is what I have so far:
<form id="" action="domain.com/" method="get">
<input type="text" name="search" />
<input type="submit" value="click here" />
</form>
The actual url result here is: domain.com/?search=vehicles
I can't figure out how to make it work
HTML forms will send the inputs in it as GET or POST (or DELETE or PUT also, I think) parameters. So they will send it as url?parameter1=xxx, they won't incorporate them in the url as you want like this url/parameter1/xxx/. I think to do it as you want is easier with jQuery (or plain javascript).
You can do this with jQuery, for example:
$("#form-id").submit(function() {
event.preventDefault(); // stops form from executing normal behavior
var newUrl = // get new url parameters and mount it;
document.location.href = newUrl; // sends to new location
/* Do Something */
return false;
});
document.location.href in javascript will redirect you to a new page.

JSP: Encoding of input parameter in form: Difference between IE and Firefox

i have a JSP with
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
in the head section, with following code i try to set the content to UTF-8:
<%#page contentType="text/html;charset=utf-8" %>
response.setCharacterEncoding("UTF-8");
request.setCharacterEncoding("UTF-8");
Within a form is an input field:
<input type="text" value="LastName*" class="input required" name="lastName" id="lastName" />
I have now problems with german special characters.
When i use request.getParameter("lastName"), this works fine in FireFox, but not in IE.
String encodedLastName = new String(request.getParameter("lastName").getBytes("iso-8859-1"), "UTF-8");
works on IE, but not in Firefox.
I tried to change everything to iso-8859-1, added accept-charset="UTF-8" to the form, ...
Now it is more guessing than working.
Can this only configured within the server (Tomcat) but why there is a difference between the behaviour of the browsers?
Thank, Markus
There were two problems which interfere with each other:
1) When using a normal post, i have to encode correct via
<%#page contentType="text/html;charset=utf-8" %>
and decode correct via
String encodedLastName = new String(request.getParameter("lastName").getBytes("iso-8859-1"), "UTF-8");
2) When using jquery, adding
contentType: 'application/x-www-form-urlencoded; charset=UTF-8'
in the $.ajax call.

ASP Sending Mail

I am a beginner at ASP programming. I am trying to figure out a simple script to send an email. This is my HTML Code:
<form method="POST" action="email.aspx">
To <input type="text" name="To"/> <br />
From <input type="text" name="From"/> <br />
Subject <input type="text" name="Subject"/> <br />
Body <textarea name="Body" rows="5" cols="20" wrap="physical" >
</textarea>
<input type="submit" />
</form>
This is my ASP code:
Dim mail
mail = Server.CreateObject('CDO.Message')
mail.To = Request.Form("To")
mail.From = Request.Form("From")
mail.Subject = Request.Form("Subject")
mail.TextBody = Request.Form("Body")
mail.Send()
Response.Write("Mail Sent!")
mail = Nothing
I know the set method is no longer supported, I am getting errors with the ASP code, are there any solutions to sending a simple email in ASP? Thank you all in advance!
Your code will only work if CDO or CDONTS is installed and available on your server - though most webhosts that support Classic ASP will make this available.
In VBScript, all objects (i.e. things that aren't numbers or strings) must be assigned using the Set operator. It's silly, I know, but this is what you need to do:
Dim mail
Set mail = Server.CreateObject("CDO.Message")
mail.To = Request.Form("To")
mail.From = Request.Form("From")
mail.Subject = Request.Form("Subject")
mail.TextBody = Request.Form("Body")
mail.Send
Response.Write "Mail Sent!"
Set mail = Nothing
If your server doesn't have CDO or CDONTS installed then you'll get an error message when you call CreateObject, but you haven't listed any error messages in your original question.