How To Get Status Code Of A Post With HttpWebRequest

Apr 10, 2010

I'm trying to ping Google when my web site's sitemap is updated but I need to know which status code does Google or any other service returns. My code is below:

HttpWebRequest rqst = (HttpWebRequest)WebRequest.Create("http://search.yahooapis.com/ping?sitemap=http%3a%2f%2fhasangursoy.com.tr%2fsitemap.xml");
rqst.Method = "POST";
rqst.ContentType = "text/xml";
rqst.ContentLength = 0;
rqst.Timeout = 3000;
rqst.GetResponse();

View 2 Replies


Similar Messages:

C# - Using HttpWebRequest To POST To A Form On An Outside Server?

Jan 26, 2010

I am trying to simulate a POST to a form on an external server that does not require any authentication, and capture a sting containing the resulting page. This is what the form looks like:

<FORM METHOD="POST" ACTION="/controller" NAME="GIN">
<INPUT type="hidden" name="JSPName" value="GIN">

Field1:

<INPUT type="text" name="Field1" size="30"
maxlength="60" class="txtNormal" value="">
</FORM>

This is what my code looks like:

ASCIIEncoding encoding = new ASCIIEncoding();
string postData = "Field1=VALUE1&JSPName=GIN";
byte[] data = encoding.GetBytes(postData);
// Prepare web request...
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create("https://XXX/controller");
myRequest.Method = "POST";
myRequest.ContentType = "text/html";
myRequest.ContentLength = data.Length;
Stream newStream = myRequest.GetRequestStream();
// Send the data.
newStream.Write(data, 0, data.Length);
StreamReader reader = new StreamReader(newStream);
string text = reader.ReadToEnd();
MessageBox.Show(text);
newStream.Close();

Currently, the code returns "Stream was not readable".

View 2 Replies

C# - HttpWebRequest POST Adds A NULL Value To Form Variables

Jan 10, 2011

I am attempting to call a RESTful service using an HttpWebRequest object via POST. I am attempting to pass 1 variable with the Request body which contains a url encoded string. I see the request when it hits the server; however, it shows 2 form variables. The first is Form[null] and the second is my variable.I am attempting to locate the source of this NULL key; however, I cannot. Any ideas on how I may be able to remedy this since it's throwing issues when I attempt to use it with the Nancy web framework for .Net.

Code:

var request = WebRequest.Create("http://localhost:8888/RouteName") as HttpWebRequest;
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";[code]...

View 1 Replies

Win Form Application Freeze On HttpWebRequest File Post

Sep 3, 2010

I have an application that will upload files from my client to a web server using HttpWebRequest (with the function suggested here: [URL]

My problem is that when the file (about 10 mb in size) is being posted the whole application freezes (e.g. "application is not responding" when I try to move the window).

Do I need to put the uploading in a separate thread, or is there any other simple way solve this?

View 2 Replies

Web Forms :: Using HttpWebRequest To Post Credentials To A Remote Website?

Aug 30, 2010

I have a php website with a login page containing username and password fields with the same exact html names. I would like to have a page in my ASP.NET page with a username and a password textbox field that sends the corresponding credentials to the php website using HttpWebRequest. How would I do that and how could I check the response to see if the authentication has been successful?

View 1 Replies

Web Forms :: Post Multiple Files To A Web Form With Httpwebrequest?

Jul 3, 2010

I have a web form on a web page like this:

<form method="post" action="http://poston.domain.com/" enctype="multipart/form-data"> <input type="hidden" name="function" value="somevalue"> <input type="text" name="username" value="somevalue2"> <input type="text" name="password" value="somevalue3"> <input type="file" name="picture"> <input type="text" name="pictto" value="0"> <input type="submit" value="Send"></form>

I can post all the required data to that form on that page by calling the following function:

Public function GetResult(ByVal File As Byte)) as stringDim request As HttpWebRequest = CType(WebRequest.Create("http://poston.domain.com), HttpWebRequest)request.Method = "POST"request.KeepAlive = TrueDim boundary As String = "-------------------------" + DateTime.Now.Ticks.ToString("x")Dim header As String = vbCrLf & "--" + boundary + vbCrLfDim footer As String = vbCrLf & "--" + boundary + vbCrLfrequest.ContentType = String.Format("multipart/form-data; boundary={0}", boundary)Dim contents As StringBuilder = New StringBuilder()contents.Append(vbCrLf)contents.Append(header)contents.Append("Content-Disposition: form-data; name=""function""" & vbCrLf)contents.Append(vbCrLf)<br/>contents.Append("functionname1")contents.Append(header)contents.Append("Content-Disposition: form-data; name=""username""" & vbCrLf)contents.Append(vbCrLf)contents.Append(myusername)contents.Append(header)contents.Append("Content-Disposition: form-data; name=""password""" & vbCrLf)contents.Append(vbCrLf)contents.Append(mypassword)contents.Append(header)contents.Append("Content-Disposition: form-data; name=""pictto""" & vbCrLf)contents.Append(vbCrLf)contents.Append("0")contents.Append(header) contents.Append("Content-Disposition: form-data; name=""picture""; filename=""Untitled.jpg""" + vbCrLf)contents.Append("Content-Type: image/jpeg" + vbCrLf)contents.Append(vbCrLf)Dim BodyBytes As Byte() = Encoding.UTF8.GetBytes(contents.ToString())Dim footerBytes As Byte() = Encoding.UTF8.GetBytes(footer)request.ContentLength = BodyBytes.Length + File.Length + footerBytes.LengthDim requestStream As Stream = request.GetRequestStream()requestStream.Write(BodyBytes, 0, BodyBytes.Length)requestStream.Write(File, 0, File.Length)requestStream.Write(footerBytes, 0, footerBytes.Length)requestStream.Flush()requestStream.Close()Dim ret As String = NewStreamReader(request.GetResponse.GetResponseStream).ReadToEndreturn retend function

View 1 Replies

C# - Underlying Connection Closed On HttpWebRequest POST On Production Server?

Nov 23, 2010

I'm getting the "The underlying connection was closed: The connection was closed unexpectedly." error while trying to POST using the HttpWebRequest class on the production server, on my dev machine it works fine.

I originally tried using the WebClient class but I switched to the HttpWebRequest to try some of the suggestions I found while researching the issue (such as setting KeepAlive to false, PreAuthenticate true and ProtocolVersion to 1.0).

Since it's only happening on the production server, i'm guessing that it might have something to do with IIS.

Here's my code

[Code]....

If set the Target Framework (I used a new project for testing) to 2.0 (I didn't test every version of the framework) it works. I'm guessing that .net handles the security differently in .net 4.0.

View 3 Replies

How To Post Status Updates On Myspace Using C#

Oct 13, 2010

how can I post status updates on myspace using asp.net C# ?

View 2 Replies

Social Networking :: Post Status Updates To Twitter And Facebook

May 7, 2013

I try To integrate Fb And Twitter Integration in My Site But At A Time 1 Integration Work Both Integration Is Not Work...

View 1 Replies

Data Controls :: How To Post XML Data To Secured (SSL) Website Using HttpWebRequest

May 16, 2013

I am using HttpWebRequest to post XML data to SSL URL.

I am using .NET 4.0 and tried many things but nothing worked for me.

1. I have tried adding Cert using in request but it also fails.X509Certificate Cert

try {
ServicePointManager.ServerCertificateValidationCallback += new System.Net.Security.RemoteCertificateValidationCallback(ValidateServerCertificate);
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;

X509Certificate Cert = null

[CODE]...

View 1 Replies

File Upload With HttpWebRequest Doesn't Post The File

Jun 17, 2010

Here is my code to post the file. I use asp fileupload control to get the file stream.

HttpWebRequest requestToSender = (HttpWebRequest)WebRequest.Create [URL]
requestToSender.Method = "POST";
requestToSender.ContentType = "multipart/form-data";
requestToSender.KeepAlive = true;
requestToSender.Credentials = System.Net.CredentialCache.DefaultCredentials;
requestToSender.ContentLength = BtnUpload.PostedFile.ContentLength;
BinaryReader binaryReader = new BinaryReader(BtnUpload.PostedFile.InputStream);
byte[] binData = binaryReader.ReadBytes(BtnUpload.PostedFile.ContentLength);
Stream requestStream = requestToSender.GetRequestStream();
requestStream.Write(binData, 0, binData.Length);
requestStream.Close();
HttpWebResponse responseFromSender = (HttpWebResponse)requestToSender.GetResponse();
string fromSender = string.Empty;
using (StreamReader responseReader = new StreamReader(responseFromSender.GetResponseStream()))
{
fromSender = responseReader.ReadToEnd();
}
XMLString.Text = fromSender;

In the page load of CrossPage.aspx i have the following code

NameValueCollection postPageCollection = Request.Form;
foreach (string name in postPageCollection.AllKeys)
{
Response.Write(name + " " + postPageCollection[name]);
}
HttpFileCollection postCollection = Request.Files;
foreach (string name in postCollection.AllKeys)
{
HttpPostedFile aFile = postCollection[name];
aFile.SaveAs(Server.MapPath(".") + "/" + Path.GetFileName(aFile.FileName));
}
string strxml = "sample";
Response.Clear();
Response.Write(strxml);

I don't get the file in Request.Files. The byte array is created. What was wrong with my HttpWebRequest?

View 2 Replies

Http Status Code 401 - Customerrors For 401.2

Jan 13, 2010

I successfully implemented role based authorization in ASP.NET. When a person does not have the needed role he gets to see an error page for 401.2 not authorized.

What I would like to accomplish now is to have a custom 401 page in my application and have it redirected there via settings in the web.config. I tried this:

<customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
<error statusCode="401" redirect="NoAccess.htm" />
</customErrors>

But this does not get caught. Do I have to override it in IIS instead? I hope not as that would make getting things deployed harder.

View 1 Replies

C# - Status Code Returned From The Server Was: 500?

Feb 28, 2010

A customer using a ASP.NET program I have just sent them is experiencing the error below, I had personally tested the program on 4 web server IIS6, 7, and 7.5, on 4 different networks and I never got this, the customer is using IIS6 with .Net 2.0 (as required). The program uses Windows authentication which may or may not be part of the problem. I'm stuck I don't know where to start with this.

View 3 Replies

JQuery: Is There A Way To Show Status Msg From Code Behind?

Sep 22, 2010

i am trying to figure out how to display message box after it done executing the server side codehere is the code which works from the client side but still looking for a way to make it work from code-behind.aspx

<div id="status"></div>

script:

$("#status").fadeTo(500, 1, function() { $(this).html("You are now registered!").fadeTo(7000, 0); })

View 1 Replies

.net - Get Description For HTTP Status Code?

Aug 22, 2010

In ASP.NET you can set the Response.StatusCode to for example 404. Should the status line / description always be set? (to in this case "404 Page Not Found")

How do you get the description if you only have the code (404)? Is this somewhere in the framework or do you manually have to hardcode the descriptions?

View 3 Replies

How To Check URL's Response Status Code Without Using IP Address

Feb 1, 2011

I want to check the status code for a web url without using the IP address as I have many websites configured with the same IP and only hostname is different for them. The HttpWebRequest resolves the IP Address and use it.

View 2 Replies

AJAX :: Web Site Hangs And Gives Http Status Code 413?

Nov 11, 2010

have a web application hosted on Windows Server 2003 SP2 with IIS 6. I use ASP.net Web Forms and ASP.net AJAX.Some times, when clicking on a button to perform an action the web application does bot respond to the user.After debugging i have found that ErrorSys.WebForms.PageRequestManagerServerErrorException: An unknown error occurred while processing the request on the server. The status code returned from the server was: 413

View 3 Replies

AJAX :: JQuery: Is There A Way To Show Status Message - From Code Behind?

Sep 22, 2010

i am trying to figure out how to display message box after it done executing the server side code here is the code which works from the client side but still looking for a way to make it work from code-behind.aspx

<div id="status"></div>

script:

$("#status").fadeTo(500, 1, function() { $(this).html("You are now registered!").fadeTo(7000, 0); })

View 3 Replies

HttpHandlers / Modules :: Send A 200 Status Code If File Type .ics

Jan 8, 2011

Due to some strange things I need to write an http module that sends a status code 200 whenever it recieves a request for an .ics file. I tried to do this in the begin request setion of the http module but that doesnt seem to be soon enough.

View 1 Replies

C# - MVC: Filtering/Varying By Http Status Code In OutputCache Attribute

Jul 1, 2010

In the ASP.NET MVC site that I'm writing, I'm building a generic Error Action that is routed to by an HttpModule, following this tutorial. In this Action, I will return a View corresponding to the status code that is applied to the response inside the HttpModule (after doing this, the module transfers the request over to the Action in question).

That's all good, except that I want to implement caching. I don't want to use the OutputCache attribute without filtering/varying, because that would mean that the page would be cached once. I want the page to be cached once for every possible status code.

Is it possible to somehow filter/vary with OutputCacheAttribute's properties, so that each Response.StatusCode is cached separately?

View 1 Replies

MVC :: Want To Return A Response With Type Text/plain And Status Code 404?

Jul 26, 2010

I want to return a response with type text/plain and status code 404. How do I do that? I've found that ContentResponse allows for setting response type but how do I set response status code?

View 2 Replies

Setting Response / Status Generates "HTTP Status String Is Not Valid" Exception?

Jan 9, 2011

I'm writing an HTTP handler in ASP.NET 4.0 and IIS7 and I need to generate a file-not-found condition.

I copied the following code from Mathew McDonald's new book, Pro ASP.Net 4 in C# 2010. (The response variable is an instance of the current HttpResponse.)

response.Status = "File not found";
response.StatusCode = 404;

However, I found that the first line generates the run-time error HTTP status string is not valid.

If, instead of the lines above, I use the following:

response.Status = "404 Not found";

Then everything seems to work fine. In fact, I even see that response.StatusCode is set to 404 automatically.

My problem is that I don't want this to fail on the production server. So I'd feel much better if I could understand the "correct" way to accomplish this. Why did the first approach work for Mathew McDonald but not for me? And is the second approach always going to be reliable?

View 1 Replies

Post Code And Not Compile It Into A Dll?

Feb 19, 2010

is there a way to post asp.net code and not complie it into a dll

I would like to upload only .aspx file and the aspx.vb file. I dont want to compile it into a .dll

is there a setting or something in that I can do so I dont have to compile it?

View 1 Replies

C# - JQuery AJAX - Error Status Code - 200 - Text "parserorro | OK"

Apr 4, 2011

I'm developing an ASP.Net web site using VS 2008 and .Net Framework 3.5, and I want to use jquery ajax in a test page, the code looks like this:

C# Method
[WebMethod]
public static string test()
{
return "Server Response" ;
}
$(document).ready(function() {
$("#myDiv").click(function() {
$.ajax({
type: "POST",
url: "AjaxTest.aspx/test",
data: "",
contentType: "application/json;charset=utf-8",
dataType: "json",
success: function(msg) {
// Replace the div's content with the page
// method's return.
alert(msg.d);
},
error: function(result){
alert("error occured. Status:" + result.status
+ ' --Status Text:' + result.statusText
+ " --Error Result:" + result);
}
});
});
});

So When I use Jquery 1.4.4 like this : I get : Status 200; Status Text: OK When I use Jquery 1.5 I get: Status 200; Status Text: Parsererror So I created a new WebSite in Visual Studio, copy and pased the code there, and it works fine !!!! I can't figure out what causes the problem. Also I have used methods with parameter, and setting data:"{}", and removing data completely, but nothing seems to work. I don't know if has to do anything with the DevExpress components that I'm using or not. I also found a good answer which was working with complete method like this :

complete: function(xhr, status) {
if (status === 'error' || !xhr.responseText) {
alert("Error");
}
else {
var data = xhr.responseText;
alert(data);
//...
}
}

But I don't know if it will work fine or there might be some other problem with this method too. I also don't know how to access response data from here.

View 2 Replies

Error Handling Codestatus / "Message" To Show The Status Code (404, 500)

Mar 20, 2010

I started with error handling. I need my. "Message" to show the status code (404, 500 etc) instead of displaying text.

[Code]....

View 2 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved