zoukankan      html  css  js  c++  java
  • 一个CLI的 的例子

    1)这是CLI 调用HTTPOST例子

    #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.
    int main()
    {
       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 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 = gcnew StreamReader( receiveStream,Encoding::UTF8 );
       Console::WriteLine( "Response stream received." );
       Console::WriteLine( readStream->ReadToEnd() );
       response->Close();   readStream->Close();}
    2) 这是 CLI string^ 转 char * 例子
     
    using namespace System::Runtime::InteropServices;
    
    void MethodName()
    {
        String^ nowString = DateTime::Now.ToString("yyyy-MM-dd-HH:mm");
        IntPtr ptrToNativeString = 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::FreeHGlobal(ptrToNativeString);
            throw;
        }
        Marshal::FreeHGlobal(ptrToNativeString);
    }
  • 相关阅读:
    [原]Django调试工具--django-debug-toolbar
    [原]Redis详细配置介绍
    [转]国内外三个不同领域巨头分享的Redis实战经验及使用场景
    [原]Redis使用场景及使用经验
    [原]打造Python开发环境之Python环境
    [原]打造Python开发环境之初篇
    Mac关闭ciscovpn客户端的开机启动
    HttpResponse render render_to_response 三者的区别
    PyCharm粘贴到OneNote 2013保留代码格式的解决方案
    谁是python上最快的xlsx writer
  • 原文地址:https://www.cnblogs.com/redmondfan/p/4227458.html
Copyright © 2011-2022 走看看