loadURI

classic Classic list List threaded Threaded
12 messages Options
Reply | Threaded
Open this post in threaded view
|

loadURI

zen2 mee
Hi all,

I writting a simple XPCOM with the following code but the server script
cannot detect the postdata. Could anyone please help? Is this a bug
since the loadURI is actually doing the POST but the server cannot
detect any postdata.

Please advice.

//*******************************************************************
s = "\r\ndata=123\r\n";
var obj, iface, postdata

obj   = Components.classes["@mozilla.org/io/string-input-stream;1"];
iface = Components.interfaces.nsIStringInputStream;

postdata = obj.createInstance(iface);
postdata.setData(s, s.length);
try
{
        var nav = getWebNavigation();
        nav.loadURI("http://foobar.com", 0, null, postdata, null);
}
catch(e)
{
        alert(e);
}
_______________________________________________
Mozilla-netlib mailing list
[hidden email]
http://mail.mozilla.org/listinfo/mozilla-netlib
Reply | Threaded
Open this post in threaded view
|

Re: loadURI

Boris Zbarsky
zen wrote:
> I writting a simple XPCOM with the following code but the server script
> cannot detect the postdata. Could anyone please help? Is this a bug
> since the loadURI is actually doing the POST but the server cannot
> detect any postdata.

Does Gecko send the data to the server?  Can you check with a packet sniffer?

-Boris
_______________________________________________
Mozilla-netlib mailing list
[hidden email]
http://mail.mozilla.org/listinfo/mozilla-netlib
Reply | Threaded
Open this post in threaded view
|

Re: loadURI

zen-3
Boris Zbarsky wrote:

> zen wrote:
>
>> I writting a simple XPCOM with the following code but the server
>> script cannot detect the postdata. Could anyone please help? Is this a
>> bug since the loadURI is actually doing the POST but the server cannot
>> detect any postdata.
>
>
> Does Gecko send the data to the server?  Can you check with a packet
> sniffer?
>
> -Boris


Yes, Gecko did send data to the server. Supprisingly, the HTTP data
constructed through loadURI() is different from the HTTP data
constructed through <form action=POST>.

FYI, loadURI() construct the postdata (*refer code from 1st posting) as
HTTP data while <form action=POST> construct as Line-based text data
(both monitored from ethereal).

Where am I wrong...? Is the loadURI's aPostData argument use in this
manner? If not, how can I manipulate/append postdata? Should I use
nsIUploadStream and how should I use it?

Please advice...

-zen
_______________________________________________
Mozilla-netlib mailing list
[hidden email]
http://mail.mozilla.org/listinfo/mozilla-netlib
Reply | Threaded
Open this post in threaded view
|

Re: loadURI

zen-3
zen wrote:

> Boris Zbarsky wrote:
>
>> zen wrote:
>>
>>> I writting a simple XPCOM with the following code but the server
>>> script cannot detect the postdata. Could anyone please help? Is this
>>> a bug since the loadURI is actually doing the POST but the server
>>> cannot detect any postdata.
>>
>>
>>
>> Does Gecko send the data to the server?  Can you check with a packet
>> sniffer?
>>
>> -Boris
>
>
>
> Yes, Gecko did send data to the server. Supprisingly, the HTTP data
> constructed through loadURI() is different from the HTTP data
> constructed through <form action=POST>.
>
> FYI, loadURI() construct the postdata (*refer code from 1st posting) as
> HTTP data while <form action=POST> construct as Line-based text data
> (both monitored from ethereal).
>
> Where am I wrong...? Is the loadURI's aPostData argument use in this
> manner? If not, how can I manipulate/append postdata? Should I use
> nsIUploadStream and how should I use it?
>
> Please advice...
>
> -zen

oops... some typo error, should be the nsIUploadChannel instead
nsIUploadStream...

-zen
_______________________________________________
Mozilla-netlib mailing list
[hidden email]
http://mail.mozilla.org/listinfo/mozilla-netlib
Reply | Threaded
Open this post in threaded view
|

Re: loadURI

Boris Zbarsky
In reply to this post by zen-3
zen wrote:
> FYI, loadURI() construct the postdata (*refer code from 1st posting) as
> HTTP data while <form action=POST> construct as Line-based text data
> (both monitored from ethereal).

I'm not sure what that means.  Since you have a \r\n at the beginning of your
string, the data should end up in the request body.  Are you saying it ends up
in the headers?

> Where am I wrong...? Is the loadURI's aPostData argument use in this
> manner?

Yes, the way you're using it looks correct.

  If not, how can I manipulate/append postdata? Should I use
> nsIUploadStream and how should I use it?
>
> Please advice...
>
> -zen
_______________________________________________
Mozilla-netlib mailing list
[hidden email]
http://mail.mozilla.org/listinfo/mozilla-netlib
Reply | Threaded
Open this post in threaded view
|

Re: loadURI

zen-3
Boris Zbarsky wrote:

> zen wrote:
>
>> FYI, loadURI() construct the postdata (*refer code from 1st posting)
>> as HTTP data while <form action=POST> construct as Line-based text
>> data (both monitored from ethereal).
>
>
> I'm not sure what that means.  Since you have a \r\n at the beginning of
> your string, the data should end up in the request body.  Are you saying
> it ends up in the headers?
>
Yes, the data end up in the header, & i think it not consider as the
content of that particular HTTP post. Please refer screenshot attached.

loadURI_post.gif  - capture during loadURI performing post
form_post.gif     - capture during form action=post submited

Please advice

-zen

loadURI_post.gif (36K) Download Attachment
form_post.gif (23K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: loadURI

Boris Zbarsky
zen wrote:
> Yes, the data end up in the header, & i think it not consider as the
> content of that particular HTTP post. Please refer screenshot attached.
>
> loadURI_post.gif  - capture during loadURI performing post
> form_post.gif     - capture during form action=post submited

The main difference I see there is the lack of a Content-Type header in the
first request...

-Boris
_______________________________________________
Mozilla-netlib mailing list
[hidden email]
http://mail.mozilla.org/listinfo/mozilla-netlib
Reply | Threaded
Open this post in threaded view
|

Re: loadURI

zen-3
Boris Zbarsky wrote:

> zen wrote:
>
>> Yes, the data end up in the header, & i think it not consider as the
>> content of that particular HTTP post. Please refer screenshot attached.
>>
>> loadURI_post.gif  - capture during loadURI performing post
>> form_post.gif     - capture during form action=post submited
>
>
> The main difference I see there is the lack of a Content-Type header in
> the first request...
>
> -Boris

That's rite... but I'm not sure whether this is normal since loadURI()
has passed in the postdata as argument, and it is not send to server as
expected... Any idea on how to overcome or append the Content into same
HTTP post?
I'm totally run out of idea... anyone could HELP??

-zen
_______________________________________________
Mozilla-netlib mailing list
[hidden email]
http://mail.mozilla.org/listinfo/mozilla-netlib
Reply | Threaded
Open this post in threaded view
|

Re: loadURI

Boris Zbarsky
zen wrote:
> That's rite... but I'm not sure whether this is normal since loadURI()
> has passed in the postdata as argument

Yes, but you didn't say what sort of postdata it is; there are several different
types.

> and it is not send to server as
> expected... Any idea on how to overcome or append the Content into same
> HTTP post?

Well, you could put the Content-type header in your post data stream before the
\r\n (so you'd need a \r\n after the header, then a second \r\n to indicate end
of headers).

Alternately, you could also pass in a header stream, not just a data stream.

-Boris
_______________________________________________
Mozilla-netlib mailing list
[hidden email]
http://mail.mozilla.org/listinfo/mozilla-netlib
Reply | Threaded
Open this post in threaded view
|

Re: loadURI

zen-3
Boris Zbarsky wrote:

> zen wrote:
>
>> That's rite... but I'm not sure whether this is normal since loadURI()
>> has passed in the postdata as argument
>
>
> Yes, but you didn't say what sort of postdata it is; there are several
> different types.
>
>> and it is not send to server as expected... Any idea on how to
>> overcome or append the Content into same HTTP post?
>
>
> Well, you could put the Content-type header in your post data stream
> before the \r\n (so you'd need a \r\n after the header, then a second
> \r\n to indicate end of headers).
>
> Alternately, you could also pass in a header stream, not just a data
> stream.
>
> -Boris

How can I pass in header stream? Can you give some code illustration?
_______________________________________________
Mozilla-netlib mailing list
[hidden email]
http://mail.mozilla.org/listinfo/mozilla-netlib
Reply | Threaded
Open this post in threaded view
|

Re: loadURI

Boris Zbarsky
zen wrote:
> How can I pass in header stream? Can you give some code illustration?

Just create another string stream with the header in it, and pass it as the last
arg to loadURI.

-Boris
_______________________________________________
Mozilla-netlib mailing list
[hidden email]
http://mail.mozilla.org/listinfo/mozilla-netlib
Reply | Threaded
Open this post in threaded view
|

Re: loadURI

zen-3
Boris Zbarsky wrote:
> zen wrote:
>
>> How can I pass in header stream? Can you give some code illustration?
>
>
> Just create another string stream with the header in it, and pass it as
> the last arg to loadURI.
>
> -Boris

Thanks! it works now...
-zen
_______________________________________________
Mozilla-netlib mailing list
[hidden email]
http://mail.mozilla.org/listinfo/mozilla-netlib