//static void exoFlickr::uploadPhoto(const LLSD& args, LLImageFormatted *image, response_callback_t callback) { LLSD params(args); signRequest(params, "POST", "http://api.flickr.com/services/upload/"); // It would be nice if there was an easy way to do multipart form data. Oh well. const std::string boundary = "------------abcdefgh012345"; std::ostringstream post_stream; post_stream << "--" << boundary; // Add all the parameters from LLSD to the query. for(LLSD::map_const_iterator itr = params.beginMap(); itr != params.endMap(); ++itr) { post_stream << "\r\nContent-Disposition: form-data; name=\"" << itr->first << "\""; post_stream << "\r\n\r\n" << itr->second.asString(); post_stream << "\r\n" << "--" << boundary; } // Headers for the photo post_stream << "\r\nContent-Disposition: form-data; name=\"photo\"; filename=\"snapshot." << image->getExtension() << "\""; post_stream << "\r\nContent-Type: "; // Apparently LLImageFormatted doesn't know what mimetype it has. if(image->getExtension() == "jpg") { post_stream << "image/jpeg"; } else if(image->getExtension() == "png") { post_stream << "image/png"; } else // This will (probably) only happen if someone decides to put the BMP entry back in the format selection floater. { // I wonder if Flickr would do the right thing. post_stream << "application/x-wtf"; LL_WARNS("FlickrAPI") << "Uploading unknown image type." << LL_ENDL; } post_stream << "\r\n\r\n"; // Now we build the postdata array, including the photo in the middle of it. std::string post_str = post_stream.str(); size_t total_data_size = image->getDataSize() + post_str.length() + boundary.length() + 6; // + 6 = "\r\n" + "--" + "--" char* post_data = new char[total_data_size + 1]; memcpy(post_data, post_str.data(), post_str.length()); char* address = post_data + post_str.length(); memcpy(address, image->getData(), image->getDataSize()); address += image->getDataSize(); std::string post_tail = "\r\n--" + boundary + "--"; memcpy(address, post_tail.data(), post_tail.length()); address += post_tail.length(); llassert(address <= post_data + total_data_size /* After all that, check we didn't overrun */); // We have a post body! Now we can go about building the actual request... LLSD headers; headers["Content-Type"] = "multipart/form-data; boundary=" + boundary; // <FS:TS> Patch from Exodus: // The default timeout (one minute) isn't enough for a large picture. // 10 minutes is arbitrary, but should be long enough. LLHTTPClient::postRaw("http://api.flickr.com/services/upload/", (U8*)post_data, total_data_size, new exoFlickrUploadResponse(callback), headers, 600); // </FS:TS> // The HTTP client takes ownership of our post_data array, // and will delete it when it's done. }
//static void exoFlickr::request(const std::string& method, const LLSD& args, response_callback_t callback) { LLSD params(args); params["format"] = "json"; params["method"] = method; params["nojsoncallback"] = 1; signRequest(params, "GET", "http://api.flickr.com/services/rest/"); LLHTTPClient::get("http://api.flickr.com/services/rest/", params, new exoFlickrResponse(callback)); }
void BTCTrader::sendSellRequest ( float amount, float price ) { if ( failedLogin ) return; QString header; QNetworkReply* rpl; header = "amount="+QString::number ( amount )+"&price="+QString::number ( price ); QNetworkRequest newRequest ( QUrl ( "https://mtgox.com/api/0/sellBTC.php" ) ); signRequest ( &header, &newRequest ); rpl = request->post (newRequest, header.toStdString().c_str() ); rpl->ignoreSslErrors(); }
void BTCTrader::sendCancelOrderRequest ( QString oid, int type ) { if ( failedLogin ) return; QString header; QNetworkReply* rpl; QNetworkRequest newRequest ( QUrl ( "https://mtgox.com/api/0/cancelOrder.php" ) ); header = "oid="+oid+"&type="+QString::number(type); signRequest ( &header, &newRequest ); rpl = request->post (newRequest, header.toStdString().c_str() ); rpl->ignoreSslErrors(); }
void BTCTrader::sendOrdersRequest () { if ( failedLogin ) return; QString header; QNetworkReply* rpl; QNetworkRequest newRequest ( QUrl ( "https://mtgox.com/api/0/getOrders.php" ) ); header =""; signRequest ( &header, &newRequest ); rpl = request->post (newRequest, header.toStdString().c_str() ); rpl->ignoreSslErrors(); }
QNetworkRequest TwitterRequest::createRequest(const QUrl& requestUrl, const QString httpMethod, QVariantMap params) { QMap<QString, QString> requestHeaders; QVariantMap::const_iterator i = params.constBegin(); while (i != params.constEnd()) { requestHeaders.insert(i.key(), QUrl::toPercentEncoding(i.value().toString())); ++i; } if (!m_accessToken.isEmpty()) { requestHeaders.insert(OAUTH_TOKEN, QUrl::toPercentEncoding(m_accessToken)); } requestHeaders.insert(OAUTH_CONSUMER_KEY, QUrl::toPercentEncoding(m_consumerKey)); requestHeaders.insert(OAUTH_NONCE, QUrl::toPercentEncoding(generateNonce())); requestHeaders.insert(OAUTH_SIGNATURE_METHOD, QUrl::toPercentEncoding("HMAC-SHA1")); requestHeaders.insert(OAUTH_TIMESTAMP, QUrl::toPercentEncoding(currentTime())); requestHeaders.insert(OAUTH_VERSION, QUrl::toPercentEncoding("1.0")); // Create the base signature string and sign it with the secrets. QString signatureBaseString = createSignatureBaseString( requestUrl.toString(), requestHeaders, httpMethod); QString signature = signRequest(signatureBaseString, QString(m_consumerSecret) + '&' + m_accessTokenSecret); requestHeaders.insert(OAUTH_SIGNATURE, QUrl::toPercentEncoding(signature)); // Generate authentication headers for the request. QString authHeader = generateAuthHeader(requestHeaders); QByteArray authHeaderByteArray = authHeader.toUtf8(); QNetworkRequest request(requestUrl); request.setRawHeader(HTTP_HEADER_AUTHORIZATION, authHeaderByteArray); return request; }