首页 > 代码库 > 一个CLI的 的例子
一个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);}
一个CLI的 的例子
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。