Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #25623 > unrolled thread
| Started by | Andrew Poulos <ap_prog@hotmail.com> |
|---|---|
| First post | 2014-08-04 14:30 +1000 |
| Last post | 2014-08-11 08:44 +1000 |
| Articles | 7 — 3 participants |
Back to article view | Back to comp.lang.javascript
Post json to asp jscript Andrew Poulos <ap_prog@hotmail.com> - 2014-08-04 14:30 +1000
Re: Post json to asp jscript Martin Honnen <mahotrash@yahoo.de> - 2014-08-04 10:32 +0200
Re: Post json to asp jscript Andrew Poulos <ap_prog@hotmail.com> - 2014-08-04 18:44 +1000
Re: Post json to asp jscript Andrew Poulos <ap_prog@hotmail.com> - 2014-08-05 11:49 +1000
Re: Post json to asp jscript Andrew Poulos <ap_prog@hotmail.com> - 2014-08-10 12:21 +1000
Re: Post json to asp jscript "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2014-08-10 09:52 +0200
Re: Post json to asp jscript Andrew Poulos <ap_prog@hotmail.com> - 2014-08-11 08:44 +1000
| From | Andrew Poulos <ap_prog@hotmail.com> |
|---|---|
| Date | 2014-08-04 14:30 +1000 |
| Subject | Post json to asp jscript |
| Message-ID | <QLCdndkekoKOkELOnZ2dnUVZ_oCdnZ2d@westnet.com.au> |
I'm trying to us an elearning tracking piece of js called tincan that
posts JSON to an endpoint. The content type is set to application/json
and the request body (as IE's F12 developer console shows) is json. The
response headers give
response : HTTP/1.1 200 OK
content-length : 0
content-type : application/json; charset=utf-8
Though Chrome's developer console gives a content length of 16568.
When (on the server with classic ASP and JScript) I try
var dat = Request.Form;
or
var dat = Request.Form + "";
or
var dat = eval("(" + Request.Form + ")");
I just get 'undefined'.
My question is, if the payload is not empty why does request give undefined?
Andrew Poulos
[toc] | [next] | [standalone]
| From | Martin Honnen <mahotrash@yahoo.de> |
|---|---|
| Date | 2014-08-04 10:32 +0200 |
| Message-ID | <lrngeq$15q2$1@adenine.netfront.net> |
| In reply to | #25623 |
Andrew Poulos wrote:
> I'm trying to us an elearning tracking piece of js called tincan that
> posts JSON to an endpoint. The content type is set to application/json
> and the request body (as IE's F12 developer console shows) is json. The
> response headers give
>
> response : HTTP/1.1 200 OK
> content-length : 0
> content-type : application/json; charset=utf-8
>
> Though Chrome's developer console gives a content length of 16568.
>
> When (on the server with classic ASP and JScript) I try
>
> var dat = Request.Form;
> or
> var dat = Request.Form + "";
> or
> var dat = eval("(" + Request.Form + ")");
>
> I just get 'undefined'.
>
> My question is, if the payload is not empty why does request give
> undefined?
As far as I remember, with classic ASP the Request.Form collection is
provided for reading out the values posted by a HTML form. If you
directly post JSON then I think you need to read out the request body
with http://msdn.microsoft.com/en-us/library/ms525710%28v=vs.90%29.aspx,
only the object you get from that is a SafeArray that does not fit in
well with the JScript data types. So you need something along the lines of
var responseArray = new
VBArray(Request.BinaryRead(Request.TotalBytes)).toArray();
See
http://msdn.microsoft.com/en-us/library/ie/y39d47w8%28v=vs.94%29.aspx
for the methods.
--- news://freenews.netfront.net/ - complaints: news@netfront.net ---
[toc] | [prev] | [next] | [standalone]
| From | Andrew Poulos <ap_prog@hotmail.com> |
|---|---|
| Date | 2014-08-04 18:44 +1000 |
| Message-ID | <Ve2dnY0QT8kH1ULOnZ2dnUVZ_r2dnZ2d@westnet.com.au> |
| In reply to | #25624 |
On 4/08/2014 6:32 PM, Martin Honnen wrote:
> Andrew Poulos wrote:
>> I'm trying to us an elearning tracking piece of js called tincan that
>> posts JSON to an endpoint. The content type is set to application/json
>> and the request body (as IE's F12 developer console shows) is json. The
>> response headers give
>>
>> response : HTTP/1.1 200 OK
>> content-length : 0
>> content-type : application/json; charset=utf-8
>>
>> Though Chrome's developer console gives a content length of 16568.
>>
>> When (on the server with classic ASP and JScript) I try
>>
>> var dat = Request.Form;
>> or
>> var dat = Request.Form + "";
>> or
>> var dat = eval("(" + Request.Form + ")");
>>
>> I just get 'undefined'.
>>
>> My question is, if the payload is not empty why does request give
>> undefined?
>
> As far as I remember, with classic ASP the Request.Form collection is
> provided for reading out the values posted by a HTML form. If you
> directly post JSON then I think you need to read out the request body
> with http://msdn.microsoft.com/en-us/library/ms525710%28v=vs.90%29.aspx,
> only the object you get from that is a SafeArray that does not fit in
> well with the JScript data types. So you need something along the lines of
>
> var responseArray = new
> VBArray(Request.BinaryRead(Request.TotalBytes)).toArray();
>
> See
> http://msdn.microsoft.com/en-us/library/ie/y39d47w8%28v=vs.94%29.aspx
> for the methods.
I wishfully thought I could just use your code without without having to
do any work. Alas, I get "error '800a1395' VBArray expected".
Thanks for the advice. Now I have a direction to work to.
Andrew Poulos
[toc] | [prev] | [next] | [standalone]
| From | Andrew Poulos <ap_prog@hotmail.com> |
|---|---|
| Date | 2014-08-05 11:49 +1000 |
| Message-ID | <M_CdnalA069wpX3OnZ2dnUVZ_sWdnZ2d@westnet.com.au> |
| In reply to | #25625 |
On 4/08/2014 6:44 PM, Andrew Poulos wrote:
> On 4/08/2014 6:32 PM, Martin Honnen wrote:
>> Andrew Poulos wrote:
>>> I'm trying to us an elearning tracking piece of js called tincan that
>>> posts JSON to an endpoint. The content type is set to application/json
>>> and the request body (as IE's F12 developer console shows) is json. The
>>> response headers give
>>>
>>> response : HTTP/1.1 200 OK
>>> content-length : 0
>>> content-type : application/json; charset=utf-8
>>>
>>> Though Chrome's developer console gives a content length of 16568.
>>>
>>> When (on the server with classic ASP and JScript) I try
>>>
>>> var dat = Request.Form;
>>> or
>>> var dat = Request.Form + "";
>>> or
>>> var dat = eval("(" + Request.Form + ")");
>>>
>>> I just get 'undefined'.
>>>
>>> My question is, if the payload is not empty why does request give
>>> undefined?
>>
>> As far as I remember, with classic ASP the Request.Form collection is
>> provided for reading out the values posted by a HTML form. If you
>> directly post JSON then I think you need to read out the request body
>> with http://msdn.microsoft.com/en-us/library/ms525710%28v=vs.90%29.aspx,
>> only the object you get from that is a SafeArray that does not fit in
>> well with the JScript data types. So you need something along the
>> lines of
>>
>> var responseArray = new
>> VBArray(Request.BinaryRead(Request.TotalBytes)).toArray();
>>
>> See
>> http://msdn.microsoft.com/en-us/library/ie/y39d47w8%28v=vs.94%29.aspx
>> for the methods.
>
> I wishfully thought I could just use your code without without having to
> do any work. Alas, I get "error '800a1395' VBArray expected".
>
> Thanks for the advice. Now I have a direction to work to.
Unfortunately I can't get it to work - even trying to rewrite the page
using vbscript proved problematic - so instead I've modified tincan.js
so that when it posts it does so as a "form". Its still sending json but
not as application/json.
Andrew Poulos
[toc] | [prev] | [next] | [standalone]
| From | Andrew Poulos <ap_prog@hotmail.com> |
|---|---|
| Date | 2014-08-10 12:21 +1000 |
| Message-ID | <srydnV4_WLZgSnvOnZ2dnUVZ_gednZ2d@westnet.com.au> |
| In reply to | #25630 |
On 5/08/2014 11:49 AM, Andrew Poulos wrote:
> On 4/08/2014 6:44 PM, Andrew Poulos wrote:
>> On 4/08/2014 6:32 PM, Martin Honnen wrote:
>>> Andrew Poulos wrote:
>>>> I'm trying to us an elearning tracking piece of js called tincan that
>>>> posts JSON to an endpoint. The content type is set to application/json
>>>> and the request body (as IE's F12 developer console shows) is json. The
>>>> response headers give
>>>>
>>>> response : HTTP/1.1 200 OK
>>>> content-length : 0
>>>> content-type : application/json; charset=utf-8
>>>>
>>>> Though Chrome's developer console gives a content length of 16568.
>>>>
>>>> When (on the server with classic ASP and JScript) I try
>>>>
>>>> var dat = Request.Form;
>>>> or
>>>> var dat = Request.Form + "";
>>>> or
>>>> var dat = eval("(" + Request.Form + ")");
>>>>
>>>> I just get 'undefined'.
>>>>
>>>> My question is, if the payload is not empty why does request give
>>>> undefined?
>>>
>>> As far as I remember, with classic ASP the Request.Form collection is
>>> provided for reading out the values posted by a HTML form. If you
>>> directly post JSON then I think you need to read out the request body
>>> with http://msdn.microsoft.com/en-us/library/ms525710%28v=vs.90%29.aspx,
>>> only the object you get from that is a SafeArray that does not fit in
>>> well with the JScript data types. So you need something along the
>>> lines of
>>>
>>> var responseArray = new
>>> VBArray(Request.BinaryRead(Request.TotalBytes)).toArray();
>>>
>>> See
>>> http://msdn.microsoft.com/en-us/library/ie/y39d47w8%28v=vs.94%29.aspx
>>> for the methods.
>>
>> I wishfully thought I could just use your code without without having to
>> do any work. Alas, I get "error '800a1395' VBArray expected".
>>
>> Thanks for the advice. Now I have a direction to work to.
To anyone that might be interested, here's one "solution":
<%@ language="javascript" %>
<script runat="server" language="vbscript">
Dim vntPostedData, lngCount, bString
lngCount = Request.TotalBytes
vntPostedData = Request.BinaryRead(lngCount)
bString = binaryToString(vntPostedData)
Function binaryToString(Binary)
'SimpleBinaryToString converts binary data
' (VT_UI1 | VT_ARRAY Or MultiByte string)
' to a string (BSTR) using MultiByte VBS functions
Dim I, S
For I = 1 To LenB(Binary)
S = S & Chr(AscB(MidB(Binary, I, 1)))
Next
BinaryToString = S
End Function
</script>
<script runat="server" type="text/javascript" language="javascript">
Response.Write(bString);
</script>
Apparently in a Classic ASP page the non-default language script gets
run before the default language script.
Andrew Poulos
[toc] | [prev] | [next] | [standalone]
| From | "Evertjan." <exxjxw.hannivoort@inter.nl.net> |
|---|---|
| Date | 2014-08-10 09:52 +0200 |
| Message-ID | <XnsA385647297A09eejj99@194.109.133.133> |
| In reply to | #25668 |
Andrew Poulos <ap_prog@hotmail.com> wrote on 10 aug 2014 in
comp.lang.javascript:
> Apparently in a Classic ASP page the non-default language script gets
> run before the default language script.
Therefore there is confusing to set your
Response.Write(bString);
in its own section.
And:
1 it is customary to set the non-default language sections at the bottom,
and only define functions there to be called in the main script.
2 VBS 'Dim'-ing without 'Option Explicit' set is only window dressing.
3 for large binaries read this for faster response:
<http://www.motobit.com/tips/detpg_binarytostring/>
Try, [not tested]:
=====================
<%@ language="javascript" %>
Response.Write(bString);
<script runat="server" language="vbscript">
Function bString()
lngCount = Request.TotalBytes
vntPostedData = Request.BinaryRead(lngCount)
bString = binaryToString(vntPostedData)
End Function
Function binaryToString(Binary)
S = ""
For I = 1 To LenB(Binary)
S = S & Chr(AscB(MidB(Binary, I, 1)))
Next
BinaryToString = S
End Function
</script>
=====================
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
[toc] | [prev] | [next] | [standalone]
| From | Andrew Poulos <ap_prog@hotmail.com> |
|---|---|
| Date | 2014-08-11 08:44 +1000 |
| Message-ID | <4aWdnfQi1ckWa3rOnZ2dnUVZ_rCdnZ2d@westnet.com.au> |
| In reply to | #25669 |
On 10/08/2014 5:52 PM, Evertjan. wrote: > Andrew Poulos <ap_prog@hotmail.com> wrote on 10 aug 2014 in > comp.lang.javascript: > >> Apparently in a Classic ASP page the non-default language script gets >> run before the default language script. > > Therefore there is confusing to set your > Response.Write(bString); > in its own section. I needed to be sure that the vbs value was available to js. > And: > > 1 it is customary to set the non-default language sections at the bottom, > and only define functions there to be called in the main script. > > 2 VBS 'Dim'-ing without 'Option Explicit' set is only window dressing. > > 3 for large binaries read this for faster response: > <http://www.motobit.com/tips/detpg_binarytostring/> > > Try, [not tested]: > > ===================== > <%@ language="javascript" %> > > Response.Write(bString); > > <script runat="server" language="vbscript"> > > Function bString() > lngCount = Request.TotalBytes > vntPostedData = Request.BinaryRead(lngCount) > bString = binaryToString(vntPostedData) > End Function > > Function binaryToString(Binary) > S = "" > For I = 1 To LenB(Binary) > S = S & Chr(AscB(MidB(Binary, I, 1))) > Next > BinaryToString = S > End Function > > </script> > > ===================== Thanks. Andrew Poulos
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.javascript
csiph-web