ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Web Queries : Passing variables via POST method not working (https://www.excelbanter.com/excel-programming/417430-web-queries-passing-variables-via-post-method-not-working.html)

mister tbo

Web Queries : Passing variables via POST method not working
 
Hello !

This is my first post here, and hopefully not my last. Hope someone can
help, I'm clueless.

I have to pass a few variables to a VBA Web Query that uses POST method. So
far, so good. However, one of the variables is a bit tricky (it's actually a
constant), of the form "/wEWIALL337KBDgK+1+PfDwLhp" (but way longer). Excel
wont pass it as is because of the + signs. When I check out the POST data
sent with an http analyzer, I see that the pluses have become line returns !

Original : "/wEWIALL337KBDgK+1+PfDwLhp"
Becomes : "/wEWIALL337KBDgK
1
PfDwLhp"

I tried replacing the pluses by Chr(43), but the problem remains, the http
analyzer still shows the variable passed with line returns, which of course,
gives me an error page from the server.

Any clues on a workaround (pretty pretty please) ?

Thanks in advance.

PS. I'm working on Excel 2002 SP3.


Tim Williams

Web Queries : Passing variables via POST method not working
 
Can you show code ?

Basically you'll need to escape your posted parameters if the post is being
submitted as url-encoded.

For a start try replacing "+" with "%2B".

A function you could use:
http://www.csie.nctu.edu.tw/~cdsheen...-urlencode.php

Tim


"mister tbo" <mister wrote in message
...
Hello !

This is my first post here, and hopefully not my last. Hope someone can
help, I'm clueless.

I have to pass a few variables to a VBA Web Query that uses POST method.
So
far, so good. However, one of the variables is a bit tricky (it's actually
a
constant), of the form "/wEWIALL337KBDgK+1+PfDwLhp" (but way longer).
Excel
wont pass it as is because of the + signs. When I check out the POST data
sent with an http analyzer, I see that the pluses have become line returns
!

Original : "/wEWIALL337KBDgK+1+PfDwLhp"
Becomes : "/wEWIALL337KBDgK
1
PfDwLhp"

I tried replacing the pluses by Chr(43), but the problem remains, the http
analyzer still shows the variable passed with line returns, which of
course,
gives me an error page from the server.

Any clues on a workaround (pretty pretty please) ?

Thanks in advance.

PS. I'm working on Excel 2002 SP3.




mister tbo[_2_]

Web Queries : Passing variables via POST method not working
 
Thank you for your reply and help... It works ! And thanks for the link, it
will prove useful in the future :)

Anyhow, code (simplified) is now :

Const Target_URL as String = "www.website.com/login.aspx"
Const User as String = "UserId=user"
Const Password as String = "&Password=password"
[...]
Const EventValidation as String = "&__EVENTVALIDATION="
Dim EventValidation_VAL As String
EventValidation_VAL = "/wEWIALQKy5MT8AgKT0pndDAL337KBDgK+1+PfDw"
Event_Validation_VAL = Replace(EventValidation_VAL, "+", "%2B")

Dim POST_DATA as String
POST_DATA = User & Password & Var_1 & ... & EventValidation &
EventValidation_VAL

With ActiveSheet.QueryTables.Add(Connection:= _
"URL;" & Target_URL, Destination:=Cells(1, 1))
.PostText = POST_DATA
.BackgroundQuery = True
.TablesOnlyFromHTML = True
.Refresh BackgroundQuery:=False
.SaveData = True
End With

Thanks again for your help !

"Tim Williams" wrote:

Can you show code ?

Basically you'll need to escape your posted parameters if the post is being
submitted as url-encoded.

For a start try replacing "+" with "%2B".

A function you could use:
http://www.csie.nctu.edu.tw/~cdsheen...-urlencode.php

Tim


"mister tbo" <mister wrote in message
...
Hello !

This is my first post here, and hopefully not my last. Hope someone can
help, I'm clueless.

I have to pass a few variables to a VBA Web Query that uses POST method.
So
far, so good. However, one of the variables is a bit tricky (it's actually
a
constant), of the form "/wEWIALL337KBDgK+1+PfDwLhp" (but way longer).
Excel
wont pass it as is because of the + signs. When I check out the POST data
sent with an http analyzer, I see that the pluses have become line returns
!

Original : "/wEWIALL337KBDgK+1+PfDwLhp"
Becomes : "/wEWIALL337KBDgK
1
PfDwLhp"

I tried replacing the pluses by Chr(43), but the problem remains, the http
analyzer still shows the variable passed with line returns, which of
course,
gives me an error page from the server.

Any clues on a workaround (pretty pretty please) ?

Thanks in advance.

PS. I'm working on Excel 2002 SP3.






All times are GMT +1. The time now is 08:09 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com