Solved

POST method don't work, need example

Posted on 1999-01-14
10
824 Views
Last Modified: 2013-11-20
I can't get the function CHttpFile::SendRequest to work
as I use the post method. The webserver is IIS 4.0.

I'm requesting an ASP and I get a CInternetException:
no 87, "Invalid parameter" (or something like that, I use
swedish so I get the message in swedish).

Do you have any working example code using post method
in CHttpFile?
0
Comment
Question by:snilsson
  • 5
  • 3
  • 2
10 Comments
 

Expert Comment

by:NotJeff
ID: 1327668
Here is some code I use to read from an ASP page:

int CJeffsHttpConnection::ConnectToURLandRead(CString url, CString *buffer)
{
      int rval = TRUE;

      DWORD dwHttpRequestFlags =
      INTERNET_FLAG_RELOAD |
      INTERNET_FLAG_EXISTING_CONNECT |
      INTERNET_FLAG_NO_AUTO_REDIRECT |
      INTERNET_FLAG_DONT_CACHE;
      
      const TCHAR szHeaders[] = _T("Accept: text/*\r\nUser-Agent: Your Appliction\r\n");

      CString strServerName;
      CString strObject;
      INTERNET_PORT nPort;
      DWORD dwServiceType;

      if (!AfxParseURL(url, dwServiceType, strServerName, strObject, nPort) ||
            dwServiceType != INTERNET_SERVICE_HTTP)
      {
            cerr << _T("Error: can only use URLs beginning with http://") << endl;
            ThrowTearException(1);
      }

      CInternetSession inetSession;
      CHttpConnection* pHttpConection = inetSession.GetHttpConnection( (LPCTSTR) strServerName);
      CHttpFile* pHttpFile = pHttpConection->OpenRequest(CHttpConnection::HTTP_VERB_POST,
                  strObject, NULL, 1, NULL, NULL, dwHttpRequestFlags);
      
      pHttpFile->AddRequestHeaders(szHeaders);
      pHttpFile->SendRequest();
 
0
 

Author Comment

by:snilsson
ID: 1327669

The example given of NotJeff is not an POST example,
it's just a modified GET example. He doesn't supply
any parameters (like "name=joe&userid=xx") and nothing
works in his example.
I can send a POST request to the websever but it doesn't recognize the parameters.
0
 
LVL 11

Expert Comment

by:mikeblas
ID: 1327670
Odds are that you're not including the right headers with your request. Most ASP components are set up to expect a form when they receive a POST. As such, you should make sure the request you're sending is actually _sending_ a form.

You should be sending the header "Content-Type: application/x-www-form-urlencoded" with your request so the server (and the ASP processor) know you're sending along the encoded content of a form.

B ekiM

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:snilsson
ID: 1327671
I am sorry mikeblas, but I have tried those headers
and it doesn't work.

IIS 4.0 just don't recognize the parameters, it's acting
like no parameters were sent, and my Request-object on the
ASP contains nothing.

This is not easy!!

SN
0
 

Author Comment

by:snilsson
ID: 1327672
The IIS doesn't recognize the parameters I send
in my POST statement. The Request-object on the ASP
contains nothing.
0
 
LVL 11

Expert Comment

by:mikeblas
ID: 1327673
Does the ASP work from a web browser?  If so, a very direct way to solve your problem is to use the browser to work the ASP while monitoring the communication with a network sniffer. You can see the exact request sent by the browser, and then replicate that request using WININET calls.

If you don't have access to a network sniffer, write a small ISAPI filter that logs the raw request text to a file.

B ekiM
0
 

Expert Comment

by:NotJeff
ID: 1327674
My code works.  I use it in a real world released application.   On top of that I use IIS 4.0  and ASP pages to read all the application sent.  So yes the code does work.  i.e. I send
a url:  "http://www.mydomain.com/asps/validateuser.asp?Username=joe&Passcode=blow"

<body>
<% localUsername = Request.QueryString("Username") %>
<% localPasscode = Request.QueryString("Passcode") %>

<%
fp_sQry = "select * from UserListTable where  User_ID='" + cstr(localUsername) + "'"

I agree with mikeblas.  You should first make a form
and make sure you can do it with a form on a web page.
Also please see the following code on the difference between getting variables from a form and from a URL on an ASP page

<html>
<body>
<p>Name entered via form is: <%= Request.Form("Username") %> </p>
<p>Name entered via url is: <%= Request.QueryString("Username") %> </p>
0
 

Author Comment

by:snilsson
ID: 1327675

I don't know what made my program work actually, but now
it's working. From the begining I couldn't use my webbrowser
to post to my ASP as well as my MFC-appl.
I did some changes in my program but no one of the suggested
but somehow it works now.

Mikeblas: Thank you for your help and comments.

NotJeff: Your last comment shows the use of the Querystring of
the Request-object. Your also supply "http://www.mydomain.com/asps/validateuser.asp?Username=joe&Passcode=blow", and isn't that how GET is done?
Anyway I'm sorry I questioned your code so hard in the first place - I just had a bad day. Thank you too.

How can I give anyone any points now for the help?
No one directly helped me but Mikeblas or NotJeff is worth
something.
0
 

Accepted Solution

by:
NotJeff earned 80 total points
ID: 1327676
Hell I could use the points and this needs to be closed out!
0
 

Author Comment

by:snilsson
ID: 1327677
OK, NotJeff gets some easy points...
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Windows Drag & Drop Location 2 111
Separate files macro - Errors on larger data set 18 73
sum13 challenge 24 132
Modbus - whats the maximum I can store in one register? 4 81
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question