Exemplo n.º 1
0
void test_requestbuilder_BuildsWithBodyContent(void)
{
    builder.putBody("This is some data in the body.");
    builder.writeToBuffer(requestBuffer, 512);
    TEST_ASSERT_EQUAL_STRING(
        "GET / HTTP/1.1\r\n"
        "Host: www.example.com\r\n"
        "Content-Type: text/html\r\n"
        "Some-Other-Header: Some-Other-Value\r\n"
        "\r\n"
        "This is some data in the body.\r\n", requestBuffer);
}
Exemplo n.º 2
0
void test_requestbuilder_BuildsWithHeaders(void)
{
    builder.putHeader("Host", "www.example.com");
    builder.putHeader("Content-Type", "text/html");
    builder.putHeader("Some-Other-Header", "Some-Other-Value");
    builder.writeToBuffer(requestBuffer, 512);
    TEST_ASSERT_EQUAL_STRING(
        "GET / HTTP/1.1\r\n"
        "Host: www.example.com\r\n"
        "Content-Type: text/html\r\n"
        "Some-Other-Header: Some-Other-Value\r\n", requestBuffer);
}
Exemplo n.º 3
0
				QNetworkReply* Post (const QByteArray& data, const QString& format,
						QNetworkAccessManager *am) const
				{
					QUrl url ("http://dump.bitcheese.net/upload-image");
					
					RequestBuilder builder;
					builder.AddFile (format, "file", data);
					
					const QByteArray& formed = builder.Build ();
					
					QNetworkRequest request (url);
					request.setHeader (QNetworkRequest::ContentTypeHeader,
							QString ("multipart/form-data; boundary=" + builder.GetBoundary ()));
					request.setHeader (QNetworkRequest::ContentLengthHeader,
							QString::number (formed.size ()));
					return am->post (request, formed);
				}
Exemplo n.º 4
0
void test_requestbuilder_BuildsWithURLParameters(void)
{
    builder.reset();
    builder.setMethodAndURL("GET", "/update"); 
    builder.setURLParam("Param1", "Param1Value");
    builder.setURLParam("Param2", "Param2Value");
    builder.putHeader("Host", "www.example.com");
    builder.putBody(NULL);

    builder.writeToBuffer(requestBuffer, 512);

    TEST_ASSERT_EQUAL_STRING(
        "GET /update?Param1=Param1Value&Param2=Param2Value HTTP/1.1\r\n"
        "Host: www.example.com\r\n", requestBuffer); 
}
Exemplo n.º 5
0
    QNetworkReply* Post (const QByteArray& data, const QString& format,
                         QNetworkAccessManager *am) const
    {
        QUrl url ("http://imagebin.ca/upload.php");

        RequestBuilder builder;
        builder.AddPair ("t", "file");

        QString name = QString ("screenshot.%1").arg (format.toLower ());
        builder.AddPair ("name", name);
        builder.AddPair ("tags", "leechcraft");
        builder.AddPair ("adult", "f");
        builder.AddFile (format, "f", data);

        QByteArray formed = builder.Build ();

        QNetworkRequest request (url);
        request.setHeader (QNetworkRequest::ContentTypeHeader,
                           QString ("multipart/form-data; boundary=" + builder.GetBoundary ()));
        request.setHeader (QNetworkRequest::ContentLengthHeader,
                           QString::number (formed.size ()));
        return am->post (request, formed);
    }
Exemplo n.º 6
0
void test_requestbuilder_BuildsWithMethodAndURLOnly(void)
{
    builder.setMethodAndURL("GET", "/");   
    builder.writeToBuffer(requestBuffer, 512);
    TEST_ASSERT_EQUAL_STRING("GET / HTTP/1.1\r\n", requestBuffer);
}
Exemplo n.º 7
0
				QNetworkReply* Post (const QByteArray& data, const QString& format,
						QNetworkAccessManager *am) const
				{
					QUrl url ("http://savepic.ru/");

					RequestBuilder builder;
					builder.AddPair ("note", "");
					builder.AddPair ("font1", "decor");
					builder.AddPair ("font2", "20");
					builder.AddPair ("orient", "h");
					builder.AddPair ("size1", "1");
					builder.AddPair ("size2", "1024x768");
					builder.AddPair ("rotate", "00");
					builder.AddPair ("flip", "0");
					builder.AddPair ("mini", "300x225");
					builder.AddPair ("opt3[]", "zoom");
					builder.AddPair ("email", "");
					builder.AddFile (format, "file", data);

					QByteArray formed = builder.Build ();

					QNetworkRequest request (url);
					request.setHeader (QNetworkRequest::ContentTypeHeader,
							QString ("multipart/form-data; boundary=" + builder.GetBoundary ()));
					request.setHeader (QNetworkRequest::ContentLengthHeader,
							QString::number (formed.size ()));
					return am->post (request, formed);
				}