• 一个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);
    }
  • 相关阅读:
    搭建SpringCloud之注册中心Eureka
    学习角色管理模块错误总结---基于SpringMVC框架
    【转】Eclipse 单步调试
    [转]MyBatis的foreach语句详解
    解决pom.xml文件 ---- web.xml is missing and <failOnMissingWebXml> is set to true
    解决Dynamic Web Module 3.0 Requires Java 1.6 or newer
    用maven在eclipse用spring建javaweb工程(一)
    【转载】Eclipse 断点调试
    学习大神笔记之“MyBatis学习总结(三)”
    学习大神笔记之“MyBatis学习总结(二)”
  • 原文地址:https://www.cnblogs.com/redmondfan/p/4227458.html
Copyright © 2020-2023  润新知