用C ++中的pastebin读取

时间:2016-08-05 09:05:01

标签: c++ http pastebin

我正在使用c ++为xbox 360创建一个小脚本,所以我无法使用像libcurl这样的任何库来阅读网站,我想知道你们中是否有人会知道我怎么能编码这段C#代码:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/jquery.validation/1.14.0/jquery.validate.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.1/css/materialize.min.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.1/js/materialize.min.js"></script>

<form id="testForm">
<div class="input-field">
<input id="email" type="email" class="validate" required="" aria-required="true">
<label for="email" data-error="wrong email adress" data-success="right">Email</label>
<p id="clue-email" class="clue hide-on-input-message">We don't spam, never !</p>
</div>
</form>

在C ++中没有使用像libcurl这样的任何Libaries?我知道有可能我无法弄清楚这一点!任何帮助都非常感谢,因为我坚持如何在xbox脚本上阅读c ++的网站这么久!

1 个答案:

答案 0 :(得分:0)

enter image description here

C ++。Net / CLI控制台应用程序:

您与StreamReader()走在正确的轨道上。我使用StreamReader()创建了两个解决方案版本。

版本1:此代码打开WebClient(),然后将数据通过它传递到StreamReader(),并将结果逐行存储在索引字符串数组中。

#include "stdafx.h"

#using <System.dll>

using namespace System;
using namespace System::Net;
using namespace System::IO;

int main()
{
    array<String^>^ linefrompastebin = gcnew array<String^>(100000);
    int i = 0;
    int maxLines = 0;

    String^  url = "http://pastebin.com/f7KKzVyf";
    WebClient^ client = gcnew WebClient;
    Stream^ data = client->OpenRead(url);

    Console::WriteLine("Reading HTML at :  " + url + " \n\n");
    Stream^ stream = client->OpenRead(url);
    StreamReader^ reader = gcnew StreamReader(data);

    linefrompastebin[0] = "";

    //Store lines from HTML into string
    while ((linefrompastebin[i] = reader->ReadLine()) != nullptr){
        i++;
    }
    maxLines = i;

    for (i = 0; i < maxLines; i++){
        Console::WriteLine("Line " + i + " = " + linefrompastebin[i]);
    }

    Console::WriteLine("\n\n");
    Console::ReadLine();

    return 0;
}

第二版: 此代码打开WebClient(),然后将数据通过它传递到StreamReader(),并将结果存储在一个单个字符串对象中,而不是字符串数组中。

#include "stdafx.h"

#using <System.dll>

using namespace System;
using namespace System::Net;
using namespace System::IO;
int main()
{

    WebClient^ WebBrowserClient = gcnew WebClient;
    String^  url = "http://pastebin.com/f7KKzVyf";
    WebBrowserClient->Headers->Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");
    Stream^ data = WebBrowserClient->OpenRead(url );
    StreamReader^ reader = gcnew StreamReader(data);
    String^ s = reader->ReadToEnd();
    Console::WriteLine(s);
    data->Close();
    reader->Close();

    Console::ReadLine();
}