This is my first try with an API and HttpWebRequest Class in Visual Studio 2008 c++. I try to POST some variables to a link and want an link value from the API back, but I get an Response (not from API) : this->t_bbcode->Text = dataStream->ToString(); // System.Net.ConnectStream

I think there is an error in my Request.

/// Request / Bitte
 HttpWebRequest^ myReq = dynamic_cast<HttpWebRequest^>(WebRequest::Create( "" ));
 myReq->Timeout = 3000;
 myReq->ServicePoint->Expect100Continue = false;
 myReq->Method = "POST";
 String^ inputData = "protect=true links=";
 ASCIIEncoding^ encoding = gcnew ASCIIEncoding;
 array<Byte>^ byte1 = encoding->GetBytes( inputData );
 // Set the content type of the data being posted.
     myReq->ContentType = "application/x-www-form-urlencoded";
     // Set the content length of the String* being posted.
 myReq->ContentLength = byte1->Length;
 System::IO::Stream^ newStream = myReq->GetRequestStream();
 newStream->Write( byte1, 0, byte1->Length );
 Console::WriteLine( "The value of 'ContentLength' property after sending the data is {0}", myReq->ContentLength );

 /// Response / Antwort

    HttpWebResponse^ response = dynamic_cast<HttpWebResponse^>(myReq->GetResponse());
System::IO::Stream^ dataStream = response->GetResponseStream();
this->t_bbcode->Text = dataStream->ToString();

// Close the Stream Object*.

Thanks :).

Added the followings before your cpp program.

using namespace System;
using namespace System::Net;

:) :-)

Hi thanks for you answer.
I did it before, sorry it's not the whole code.
The Problem is i get from GetResponseStream() the Value System.Net.ConnectStream instead of an answer from the webserver.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.