 |
|
 |
First i want to thank you for this article,and i want to know if exist a way to redirect to the page that receive the generated xml to display it on this page??
thankssdfrt
|
|
|
|
 |
|
|
 |
|
 |
Why not? Are you offended by the supplied knowledge? Or if you have a better solution, please feel free to contribute. Thanks.
|
|
|
|
 |
|
 |
Thanks to this article, am able to post large data to my webpage, so that I need not make direct contact to my database and use my page as an adapter to store data in my database.
|
|
|
|
 |
|
 |
Thanks nice and useful.....
I needed to see the response from the XML post which I did like this....
StreamReader sr = new StreamReader( rsp.GetResponseStream());
string cresponse = sr.ReadToEnd();
|
|
|
|
 |
|
|
 |
|
 |
Please can I also have the code
|
|
|
|
 |
|
 |
Please cut copy the code in a C# project and it should fine..
|
|
|
|
 |
|
 |
Thanks for the code here, especially the guy who provide the whole complete running code.
|
|
|
|
 |
|
 |
i want to post a string to an url using C++\CLI
Naveen
|
|
|
|
 |
|
 |
Hi,
I am using an html page in my application
and my application is written in .net except this page.
I need to call the database values (SQL Server 2005) into that html page
How can I achive this...
Please help me out.
Its very urgent need for me .
Thanks in adavance,
Anand
|
|
|
|
 |
|
 |
Hi Anand,
Why don't you generate HTML file dynamically in your .NET code or use AJAX.
Cheers,
Sanjay
|
|
|
|
 |
|
 |
Hi Sanjay,
I have a requirement that,
I have to take the htm extension page only and in that I have to get the values from the SQL Server 2005.
I have used the Dynamic html in so many cases. I know how to get the values in that case. But this time I am not getting how to get the values.
I have finished all the task which I have assingned except this..
Once I succeded in this then my task for this day will be completed
so, Please if you know how to get the values, please help me out
Thanks,
Anand
|
|
|
|
 |
|
 |
I have used the HttpWebrequest before but never set up a Server side page in .NET to receive the XML string.
I tried the code, but couldn't make it work. I am getting the error
"The remote server returned an error: (405) Method Not Allowed"
Here is the code, any help would be greatly appreciated!
Default.aspx
------------
<@>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> Default Page<title>
</title></title></head>
<body>
<form id="receiveXML" runat="server" method="POST">
</form>
<body>
<html>
Deafult.Aspx.CS
---------------
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string xmlString = string.Empty;
this.Response.ContentType = "text/xml";
StreamReader streamReader = new StreamReader(Page.Request.InputStream);
xmlString = streamReader.ReadToEnd();
}
} </html></body></body></html>
|
|
|
|
 |
|
 |
I've got this piece of code, originated from Alex Feinman, which is intended to upload XML files from Pocket PC to an IIS virtual directory. It used to run smoothly under IIS 5, but as soon as I put it to run under IIS 6 it refused to work. The log file tells me that :
2006-11-01 14:52:59 192.168.0.38 1224 192.168.0.11 80 HTTP/1.1 PUT /tr/0220061101122605000000001JR.xml 400 1 BadRequest DefaultAppPool
2006-11-01 14:53:43 192.168.0.38 1224 192.168.0.11 80 HTTP/1.1 PUT /tr/0220061101122605000000001JR.xml 400 1 Connection_Dropped DefaultAppPool
2006-11-01 14:58:41 192.168.0.38 1236 192.168.0.11 80 HTTP/0.0 Invalid - 400 - Verb -
2006-11-01 14:58:45 192.168.0.38 1237 192.168.0.11 80 HTTP/0.0 Invalid - 400 - Verb -
and once :
2006-11-01 14:52:59 192.168.0.38 1224 192.168.0.11 80 HTTP/1.1 PUT /tr/0220061101122605000000001JR.xml 400 1 BadRequest DefaultAppPool
2006-11-01 14:53:43 192.168.0.38 1224 192.168.0.11 80 HTTP/1.1 PUT /tr/0220061101122605000000001JR.xml 400 1 Connection_Dropped DefaultAppPool
2006-11-01 14:58:41 192.168.0.38 1236 192.168.0.11 80 HTTP/0.0 Invalid - 400 - Verb -
2006-11-01 14:58:45 192.168.0.38 1237 192.168.0.11 80 HTTP/0.0 Invalid - 400 - Verb -
Now, is there anything I can do to make it run under IIS 6 ?
Code follows. Thanks very much !
Jr
Public Function UploadIt(Optional ByVal logErrors As Boolean = False) As Integer
'Alex Feinman code next
Dim i, j As Integer
Dim data As String
Dim Url As String
Dim mstrFilename As String
Dim req As HttpWebRequest
Dim resp As HttpWebResponse ' = Nothing
Dim reqStream As Stream
Dim code As HttpStatusCode
Dim ascii As Encoding
Dim mblnFileRead As Boolean
Dim muriURI As Uri
Dim mblnFileSent As Boolean
Dim mblnURIOk As Boolean
If Me.Files.Count = 0 Or mstrWhereTo = "" Then Exit Function
j = Me.Files.Count - 1
Url = mstrWhereTo
If Right(Url, 1) <> "/" Then
Url = Url & "/"
End If
ascii = Encoding.ASCII
For i = 0 To j
Try
Dim rdr As New StreamReader(Me.Files.Item(i).FileNameAndPath)
data = rdr.ReadToEnd
rdr.Close()
rdr = Nothing
mblnFileRead = True
Catch ex As Exception
If logErrors Then
TextLogger.Log(ex.Message & " in HTTPUpload.UploadIt (data assignment)")
End If
mblnFileRead = False
End Try
If mblnFileRead Then
'Build the target url from the virtual directory and file name
mstrFilename = Path.GetFileName(Me.Files.Item(i).FileNameAndPath)
'If web server is running UrlScan it will reject .exe file as an unsafe extension
'If Path.GetExtension(mstrFilename) = ".exe" Then
'mstrFilename = Path.ChangeExtension(mstrFilename, "ex_")
'End If
'Make sure the url is properly escaped. Uri class takes care of that
Try
muriURI = New Uri(Url & mstrFilename)
req = WebRequest.Create(muriURI) 'HttpWebRequest.Create(muriURI)
muriURI = Nothing
mblnURIOk = True
Catch ufwe As UriFormatException
If logErrors Then
TextLogger.Log(ufwe.Message & " in HTTPUpload.UploadIt (URI and WebRequest instantiation)")
End If
mblnURIOk = False
Catch ex As Exception
If logErrors Then
TextLogger.Log(ex.Message & " in HTTPUpload.UploadIt (URI and WebRequest instantiation)")
End If
mblnURIOk = False
End Try
If mblnURIOk Then
'req.Pipelined = True
'req.KeepAlive = True
req.Method = "PUT"
req.AllowWriteStreamBuffering = True
req.ContentType = "text/xml"
req.Timeout = 1 * 30 * 1000 'half a minute timeout
'req = CType(WebRequest.Create(Url), HttpWebRequest)
'req = CType(WebRequest.Create(mstrWhereTo), HttpWebRequest)
If mstrUserName <> "" And mstrPassword <> "" Then
'req.AllowWriteStreamBuffering = True
req.Credentials = New NetworkCredential(mstrUserName, mstrPassword)
'Else
'req.Credentials = CredentialCache.DefaultCredentials
End If
'For large files (> 50KB) you may want to uncomment the next line
'req.SendChunked = true;
req.ContentLength = data.Length
Try
reqStream = req.GetRequestStream()
Dim maContents() As Byte = ascii.GetBytes(data)
reqStream.Write(maContents, 0, maContents.Length) 'data.Length)
reqStream.Flush()
reqStream.Close()
'reqStream = Nothing
maContents = Nothing
mblnFileSent = True
Me.Files.Item(i).Sent = True
Catch wex As WebException
If logErrors Then
TextLogger.Log(wex.Message & " in HTTPUpload.UploadIt (WebException in GetRequestStream)")
End If
mblnFileSent = False
Catch ufwe As UriFormatException
If logErrors Then
TextLogger.Log(ufwe.Message & " in HTTPUpload.UploadIt (UriFormatWebException in GetRequestStream)")
End If
mblnFileSent = False
Catch ex As Exception
If logErrors Then
TextLogger.Log(ex.Message & " in HTTPUpload.UploadIt (Exception in GetRequestStream)")
End If
mblnFileSent = False
'Me.Files.Item(i).Sent = False
End Try
'If mblnFileSent Then
Try
resp = req.GetResponse()
code = resp.StatusCode
If code.ToString = "OK" Or code.ToString = "Created" Then
Me.Files.Item(i).Sent = True
End If
Catch ex As Exception
If logErrors Then
TextLogger.Log(ex.Message & " in HTTPUpload.UploadIt (in GetResponse)")
End If
Finally
resp.Close()
End Try
'End If
End If
req = Nothing
End If
Next
reqStream = Nothing
ascii = Nothing
UploadIt = 1
'code = resp.StatusCode
End Function
|
|
|
|
 |
|
 |
I just checked up the .NET SDK and find out which namespace defines Web req and rsp.
Here is hole cs file(the one that sends xml). I made a button_click enevt that fires up posting of vehicle.xml. Other cs file:-> works fine. Just import System.IO;
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Net;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Xml;
using System.IO;
namespace Testing
{
///
/// Summary description for PostXml.
///
public class PostXml : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Button PostXmlButton;
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
this.PostXmlButton.Click += new System.EventHandler(this.PostXmlButton_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void PostXmlButton_Click(object sender, System.EventArgs e)
{
WebRequest req = null;
WebResponse rsp = null;
try
{
string fileName = @"C:\Inetpub\wwwroot\Exercises\Testing\vehicles.xml";
string uri = @"http://localhost/Exercises/Testing/RecieveXml.aspx";
req = WebRequest.Create(uri);
req.Method = "POST";
req.ContentType = "text/xml";
StreamWriter writer = new StreamWriter(req.GetRequestStream());
// Write the xml text into the stream
writer.WriteLine(this.GetTextFromXMLFile(fileName));
writer.Close();
Label1.Text = "Det gikk greit, Sjekk ReceiveXml.aspx nu!";
// Send the data to the webserver
rsp = req.GetResponse();
}
catch(WebException webEx)
{
}
catch(Exception ex)
{
}
finally
{
if(req != null) req.GetRequestStream().Close();
if(rsp != null) rsp.GetResponseStream().Close();
}
}
///
/// Read xml data from file
///
///
/// returns file content in xml string format
private string GetTextFromXMLFile(string file)
{
StreamReader reader = new StreamReader(file);
string ret = reader.ReadToEnd();
reader.Close();
return ret;
}
}
}:->
//by Rezer
|
|
|
|
 |
|
 |
I'm a newby to c#, and this bit of code is excatly what I'm looking for. Could you post all of the code so that we can test the code ourselves. Your code looks to have what I need, but I can't seem to make it work correctly.
|
|
|
|
 |
|
 |
It's exactly what I'm trying to do but It doesn't work for me
(VS2005 .Net framework 2.0)
Marc
|
|
|
|
 |
|
 |
I have been wondering if I should use XML or POST data to request a customized "web service" I have developed some time ago (for PHP/Flash), and now I'm porting the application to ASP.NET/Flash.
This is quite easier than I was thinking. Thank you so much!!
And for you who don't know what this can be useful for...
Web Services strongly depend on sending XML formatted request to the server and expecting some XML response. Using regular input (POST,GET) you cannot do that, you need to have access to the "raw" xml sent by the client. And that is what this script/tuto/sample is about.
===
BTW, When I get into a tutorial and I have no idea what the code is for, and what they're talking about, I just realize that I'm not it's intended audience, and not blame them for that. Just turn the page. That's my point of view, no offense.
Manoloweb
|
|
|
|
 |
|
 |
A friendly reminder :
It would have been nice if you could have given some background description of the code, its purpose and the intended use. Just a code does not help me if I do not know how should I use this.
|
|
|
|
 |