An example of a CLI

Source: Internet
Author: User

1) This is the CLI call Httpost example

#using <System.dll>

Using Namespace System;
Using Namespace System::Net;
Using Namespace System::Text;
Using Namespace System::Io;

Specify the URL to receive the request.
IntMain()
{
Array<String^>^Args= Environment::GetCommandLineArgs();
HttpWebRequest^Request= dynamic_cast<HttpWebRequest^> (WebRequest::Create(Args[ 1 ] ));

Set some reasonable limits on resources used by this request
Request-Maximumautomaticredirections = 4;
Request-maximumResponseHeadersLength = 4;

Set credentials to use for the this request.
Request-Credentials = CredentialCache::DefaultCredentials;
HttpWebResponse^Response= dynamic_cast<HttpWebResponse^> (Request-GetResponse());
Console::WriteLine( "Content length is {0}",Response-ContentLength );
Console::WriteLine( "Content type is {0}",Response-ContentType );

Get the stream associated with the response.
Stream^Receivestream=Response-GetResponseStream();

Pipes the stream to a higher level stream reader with the required encoding format.
StreamReader^Readstream=GcnewStreamReader( Receivestream,encoding:: utf8 );
   console::writeline< Span class= "pun" > ( );
   console::writeline< Span class= "pun" > ( Readstream->readtoend );    response->close ();    Readstream->close ();}
2) This is the CLI string^ turn char * example
Using Namespace System::Runtime::InteropServices;void MethodName(){ String^Nowstring= Datetime::Now.Tostring("Yyyy-mm-dd-hh:mm"); IntPtrPtrtonativestring= Marshal::StringToHGlobalAnsi(Nowstring); Try { Cvcapture*Capture=Cvcreatecameracapture(0); Iplimage*Tosave=Cvqueryframe(Capture);Cvsaveimage(Static_cast<Char*> (Ptrtonativestring.ToPointer()),Tosave);Cvreleaseimage(&Tosave Cvreleasecapture (&capture } catch  ( ...)  { marshal:: Freehglobalptrtonativestring throw;} marshal:: Freehglobalptrtonativestring               /span>                

An example of a CLI

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.