|
1 /** |
|
2 * Copyright (c) 2010 Sasken Communication Technologies Ltd. |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the "{License}" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "{LicenseUrl}". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Narasimhulu Kavadapu, Sasken Communication Technologies Ltd - Initial contribution |
|
11 * |
|
12 * Contributors: |
|
13 * Siddhartha Chandra, Sasken Communication Technologies Ltd |
|
14 * Description: |
|
15 * class to handle calls to rest Server API's |
|
16 */ |
|
17 |
|
18 #include "requestSP.h" |
|
19 #include "sessionSP.h" |
|
20 #include "xmlParser.h" |
|
21 #include "errorCodes.h" |
|
22 |
|
23 #include <QNetworkRequest> |
|
24 #include <QXmlSimpleReader> |
|
25 #include <QXmlInputSource> |
|
26 #include <QCryptographicHash> |
|
27 #include <QtAlgorithms> |
|
28 #include <QDebug> |
|
29 |
|
30 #include "hash.h" |
|
31 |
|
32 #include <keys.h> |
|
33 #include <qnetworkproxy.h> |
|
34 #include <QSslConfiguration> |
|
35 /////////////////////////////////////////////////////////////////////////////////////////////////// |
|
36 // global |
|
37 |
|
38 static const QString kAPIVersion = "1.0"; |
|
39 static const QString kAPIFormat = "XML"; |
|
40 static const QString kStringBoundary = "3i2ndDfv2rTHiSisAbouNdArYfORhtTPEefj3q2f"; |
|
41 |
|
42 /////////////////////////////////////////////////////////////////////////////////////////////////// |
|
43 |
|
44 static bool caseInsensitiveLessThan(const QString &s1, const QString &s2) |
|
45 { |
|
46 return s1.toLower() < s2.toLower(); |
|
47 } |
|
48 |
|
49 /////////////////////////////////////////////////////////////////////////////////////////////////// |
|
50 // Static class functions |
|
51 |
|
52 FBRequest* FBRequest::request() |
|
53 { |
|
54 return FBRequest::requestWithSession(FBSession::session()); |
|
55 } |
|
56 |
|
57 FBRequest* FBRequest::requestWithSession (FBSession* aSession) |
|
58 { |
|
59 FBRequest* request = new FBRequest(aSession); |
|
60 return request; |
|
61 } |
|
62 |
|
63 /////////////////////////////////////////////////////////////////////////////////////////////////// |
|
64 // instance public functions |
|
65 FBRequest::FBRequest(FBSession* aSession) : iSession ( aSession ), iNetworkAccessManager ( this ) |
|
66 {} |
|
67 |
|
68 const QDateTime& FBRequest::timeStamp() const |
|
69 { |
|
70 return iTimestamp; |
|
71 } |
|
72 |
|
73 void FBRequest::connect() |
|
74 { |
|
75 qDebug()<<"Inside FBRequest::connect()"; |
|
76 //emit requestLoading(); |
|
77 |
|
78 /*QString url ; |
|
79 url = iUrl; |
|
80 qDebug()<<"url"<<url;*/ |
|
81 |
|
82 QNetworkRequest request; |
|
83 |
|
84 QSslConfiguration config( QSslConfiguration::defaultConfiguration() ); |
|
85 request.setSslConfiguration( config ); |
|
86 |
|
87 //request.setUrl(QUrl(url)); |
|
88 QUrl myurl = kRequestTokenUrl; |
|
89 request.setUrl(myurl); |
|
90 |
|
91 /* from the Qt docs on QNetworkAccessManager: |
|
92 QNetworkAccessManager by default does not have a set cache. |
|
93 Qt provides a simple disk cache, QNetworkDiskCache, which can be used. |
|
94 |
|
95 However we will not use it.*/ |
|
96 QString Authorization = "OAuth oauth_nonce=\"" + iSession->stroauth_nonce + "\", oauth_signature_method=\"HMAC-SHA1\", oauth_timestamp=\"" + iSession->stroauth_timestamp + "\", oauth_consumer_key=\"" + kConsumerKey + "\", oauth_signature=\"" + iSession->stroauth_signature.toAscii().toPercentEncoding() + "\", oauth_version=\"1.0\""; |
|
97 qDebug()<<"Authorization: "<<Authorization; |
|
98 QByteArray auth = Authorization.toUtf8(); |
|
99 qDebug()<<"auth:"<<auth; |
|
100 request.setRawHeader("Authorization",auth); |
|
101 const QString contentType = "multipart/form-data; boundary=" + kStringBoundary; |
|
102 request.setHeader (QNetworkRequest::ContentTypeHeader, contentType); |
|
103 //request.setRawHeader("User-Agent", kUserAgent); |
|
104 //request.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::AlwaysNetwork); |
|
105 // request.setAttribute(QNetworkRequest::CacheSaveControlAttribute, false); |
|
106 |
|
107 //iTimestamp = QDateTime::currentDateTime(); |
|
108 |
|
109 //if (iMethod.length()) |
|
110 //{ |
|
111 // const QString contentType = "multipart/form-data; boundary=" + kStringBoundary; |
|
112 // request.setRawHeader("Content-Type", contentType.toUtf8()); |
|
113 |
|
114 /* connect all signals from iNetWorkAccessManager to this */ |
|
115 QByteArray postBody ; |
|
116 generatePostBody (postBody); |
|
117 postBody = ""; |
|
118 pbar = new progressbar; |
|
119 pbar->show(); |
|
120 proxysettings(); |
|
121 QNetworkReply* reply = iNetworkAccessManager.post(request, postBody); |
|
122 |
|
123 QObject::connect(reply, SIGNAL(finished()), this, SLOT(networkReplyFinished())); |
|
124 QObject::connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), |
|
125 this, SLOT(networkReplyError(QNetworkReply::NetworkError))); |
|
126 |
|
127 //} |
|
128 } |
|
129 void FBRequest::proxysettings() |
|
130 { |
|
131 #ifdef EMULATORTESTING |
|
132 qDebug()<<"proxysettings"; |
|
133 |
|
134 // Reading the keys, CSM Stubbed - START |
|
135 QFile file("c:\\data\\DoNotShare.txt"); |
|
136 if (!file.open(QIODevice::ReadOnly)) |
|
137 { |
|
138 qDebug()<<"File to read the windows username and password could not be opened, returning!!!"; |
|
139 return; |
|
140 } |
|
141 |
|
142 QByteArray arr = file.readAll(); |
|
143 QList<QByteArray> list = arr.split(' '); |
|
144 file.close(); |
|
145 |
|
146 QString username(list[0]); |
|
147 QString password(list[1]); |
|
148 |
|
149 QString httpProxy = "10.1.0.214";//ipwproxy.sasken.com |
|
150 QString httpPort = "3128"; |
|
151 |
|
152 QString httpUser =username;/* This could be taken thru an QDialog implmentation to remove the Hard coding */ |
|
153 QString httpPass =password;/* This could be taken thru an QDialog implmentation to remove the Hard coding */ |
|
154 |
|
155 /*==Classes used from Network Module==*/ |
|
156 QNetworkProxy proxy; |
|
157 |
|
158 proxy.setType(QNetworkProxy::HttpProxy); |
|
159 proxy.setHostName(httpProxy); |
|
160 proxy.setPort(httpPort.toInt()); |
|
161 proxy.setUser(httpUser); |
|
162 proxy.setPassword(httpPass); |
|
163 |
|
164 QNetworkProxy::setApplicationProxy(proxy); |
|
165 #endif |
|
166 } |
|
167 /////////////////////////////////////////////////////////////////////////////////////////////////// |
|
168 // instance private functions |
|
169 QString FBRequest::sha1() |
|
170 { |
|
171 qDebug()<<"Insha1"; |
|
172 CSHA1* sha=CSHA1::NewL(); |
|
173 TBuf8<100> keyVal; |
|
174 keyVal.Copy(_L8("sasken")); |
|
175 CHMAC* hmac=CHMAC::NewL(keyVal,sha); |
|
176 //TBuf8<1024> baseString; |
|
177 TPtrC8 hashedSig(hmac->Hash(_L8("sasken"))); |
|
178 TBuf8<1024>bufr; |
|
179 bufr.Copy(hashedSig); |
|
180 QByteArray digest = QByteArray::fromRawData((char*)bufr.Ptr(),bufr.Length()); |
|
181 qDebug()<<"digest.toHex();"<<digest.toHex(); |
|
182 |
|
183 if(hmac) |
|
184 { |
|
185 delete hmac; |
|
186 hmac=NULL; |
|
187 } |
|
188 /* TBuf8<1024>bufr; |
|
189 bufr.Copy(hashedSig); |
|
190 QByteArray digest = QByteArray::fromRawData((char*)bufr.Ptr(),bufr.Length()); |
|
191 qDebug()<<"digest.toHex();"<<digest.toHex(); |
|
192 qDebug()<<"digest"<<digest;*/ |
|
193 return digest.toHex(); |
|
194 } |
|
195 |
|
196 bool FBRequest::isSpecialMethod() const { |
|
197 return ( iMethod.compare("facebook.auth.getSession", Qt::CaseInsensitive) == 0 |
|
198 || iMethod.compare("facebook.auth.createToken", Qt::CaseInsensitive) == 0 ); |
|
199 } |
|
200 |
|
201 QString FBRequest::urlForMethod (const QString& aMethod) const { |
|
202 |
|
203 Q_UNUSED(aMethod) |
|
204 return iSession->apiURL(); |
|
205 } |
|
206 |
|
207 QString FBRequest::generateGetURL() const |
|
208 { |
|
209 qDebug()<<"Inside FBRequest::generateGetURL()"; |
|
210 const QUrl url(iUrl); |
|
211 const QString queryPrefix = url.hasQuery() ? "&" : "?"; |
|
212 |
|
213 QStringList pairs; |
|
214 DictionaryIterator i(iParams); |
|
215 |
|
216 while (i.hasNext()) { |
|
217 i.next(); |
|
218 pairs << i.key().toUtf8() + "=" + i.value().toUtf8(); |
|
219 } |
|
220 |
|
221 return iUrl + queryPrefix + pairs.join("&"); |
|
222 } |
|
223 |
|
224 QString FBRequest::generateCallId() const { |
|
225 QDateTime dateTime = QDateTime::currentDateTime(); |
|
226 uint secs = dateTime.toTime_t(); |
|
227 QString result = QString::number(secs, 10); |
|
228 return result; |
|
229 } |
|
230 /* |
|
231 * |
|
232 httpMethod + "&" + |
|
233 url_encode( base_uri ) + "&" + |
|
234 sorted_query_params.each { | k, v | |
|
235 url_encode ( k ) + "%3D" + |
|
236 url_encode ( v ) |
|
237 }.join("%26") |
|
238 * |
|
239 */ |
|
240 QString FBRequest::generateSig(Dictionary Params) |
|
241 { |
|
242 QString joined; |
|
243 joined = "POST"; |
|
244 joined += "&"; |
|
245 joined += kRequestTokenUrl.toAscii().toPercentEncoding() + "&"; |
|
246 |
|
247 QStringList keys = Params.keys(); |
|
248 qSort(keys.begin(), keys.end(), caseInsensitiveLessThan); |
|
249 QListIterator<QString> i(keys); |
|
250 int count = 0; |
|
251 while (i.hasNext()) |
|
252 { |
|
253 count++; |
|
254 if(count > 1) |
|
255 joined.append("%26"); |
|
256 const QString key = i.next(); |
|
257 joined.append(key.toAscii().toPercentEncoding()); |
|
258 joined.append("%3D"); |
|
259 joined.append(Params.value(key).toAscii().toPercentEncoding()); |
|
260 } |
|
261 qDebug()<<"joined"<<joined; |
|
262 //uncomment for testing key |
|
263 //joined = "POST&https%3A%2F%2Fapi.twitter.com%2Foauth%2Frequest_token&oauth_callback%3Dhttp%253A%252F%252Flocalhost%253A3005%252Fthe_dance%252Fprocess_callback%253Fservice_provider_id%253D11%26oauth_consumer_key%3DGDdmIQH6jhtmLUypg82g%26oauth_nonce%3DQP70eNmVz8jvdPevU3oJD2AfF7R7odC2XJcn4XlZJqk%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1272323042%26oauth_version%3D1.0"; |
|
264 TBuf<1024> sid(joined.utf16()); |
|
265 |
|
266 QByteArray digest1 = QByteArray::fromRawData((char*)sid.Ptr(),sid.Length()); |
|
267 qDebug()<<"digest1: "<<digest1; |
|
268 TBuf8<1024>buff;//(sid); |
|
269 buff.Copy(sid); |
|
270 QByteArray digest2 = QByteArray::fromRawData((char*)buff.Ptr(),buff.Length()); |
|
271 qDebug()<<"digest2: "<<digest2; |
|
272 |
|
273 //signature |
|
274 CSHA1* sha=CSHA1::NewL(); |
|
275 //uncomment for testing key |
|
276 //QByteArray key= "MCD8BKwGdgPHvAuvgvz4EQpqDAtx89grbuNMRd7Eh98"; |
|
277 QByteArray key= kConsumerSecret.toUtf8(); |
|
278 key = key.toPercentEncoding(); |
|
279 key.append("&"); |
|
280 key.append(iSession->stroauth_TokenSecret.toUtf8().toPercentEncoding()); |
|
281 qDebug()<<"Key:"<<key; |
|
282 TPtrC8 myDataDescriptor( reinterpret_cast<const TText8*> (key.constData()),key.size()); |
|
283 |
|
284 //Take a copy of the data |
|
285 HBufC8* buffer12 = HBufC8::New(myDataDescriptor.Length()); |
|
286 |
|
287 Q_CHECK_PTR(buffer12); |
|
288 buffer12->Des().Copy(myDataDescriptor ); |
|
289 TPtr8 tptr = buffer12->Des(); |
|
290 |
|
291 TBuf8<100> keyVal; |
|
292 keyVal.Copy(tptr); |
|
293 |
|
294 CHMAC* hmac=CHMAC::NewL(keyVal,sha); |
|
295 |
|
296 TPtrC8 hashedSig(hmac->Hash(buff)); |
|
297 TBuf8<1024>bufr; |
|
298 bufr.Copy(hashedSig); |
|
299 QByteArray digest = QByteArray::fromRawData((char*)bufr.Ptr(),bufr.Length()); |
|
300 qDebug()<<"digest.toHex() "<<digest.toHex(); |
|
301 QByteArray base64 = digest.toBase64(); |
|
302 qDebug()<<"Base64 Encoded "<<base64; |
|
303 if(hmac) |
|
304 { |
|
305 delete hmac; |
|
306 hmac=NULL; |
|
307 } |
|
308 |
|
309 return base64; |
|
310 } |
|
311 |
|
312 void FBRequest::generatePostBody( QByteArray& body ) |
|
313 { |
|
314 qDebug()<<"Inside FBRequest::generatePostBody()"; |
|
315 QString endLine = "\r\n--" + kStringBoundary + "\r\n"; |
|
316 body.append( "--" + kStringBoundary.toUtf8() + "\r\n" ) ; |
|
317 |
|
318 |
|
319 DictionaryIterator i (iParams); |
|
320 |
|
321 while (i.hasNext()) |
|
322 { |
|
323 i.next(); |
|
324 |
|
325 body.append("Content-Disposition: form-data; name=\"" + i.key().toUtf8() + "\"\r\n\r\n" ); |
|
326 body.append(i.value().toUtf8()); |
|
327 body.append(endLine.toUtf8()); |
|
328 } |
|
329 |
|
330 |
|
331 if (iDataParam.size()) |
|
332 { |
|
333 if (iDataParamPicture) |
|
334 { |
|
335 body.append("Content-Disposition: form-data; filename=\"photo\"\r\n" ); |
|
336 body.append("Content-Type: image/png\r\n\r\n" ); |
|
337 } |
|
338 else |
|
339 { |
|
340 body.append("Content-Disposition: form-data; filename=\"data\"\r\n"); |
|
341 body.append("Content-Type: content/unknown\r\n\r\n"); |
|
342 } |
|
343 |
|
344 body.append(iDataParam); |
|
345 body.append(endLine.toUtf8()); |
|
346 |
|
347 } |
|
348 } |
|
349 |
|
350 void FBRequest::handleResponseData( const QByteArray& aResponseData ) |
|
351 { |
|
352 qDebug()<<"Inside FBRequest::handleResponseData()"; |
|
353 FBError error; |
|
354 QVariant result = parseXMLResponse( aResponseData, error); |
|
355 if (error.code() != 0) |
|
356 { |
|
357 emit requestFailedWithFacebookError(error); |
|
358 } |
|
359 else |
|
360 { |
|
361 emit requestDidLoad(result); |
|
362 } |
|
363 |
|
364 delete pbar; |
|
365 } |
|
366 |
|
367 void FBRequest::post( const QString& aUrl, const Dictionary& aParams) |
|
368 { |
|
369 qDebug()<<"Inside FBRequest::post()"; |
|
370 iUrl = aUrl; |
|
371 iParams = aParams; |
|
372 |
|
373 iSession->send(this); |
|
374 } |
|
375 |
|
376 void FBRequest::cancel() |
|
377 { |
|
378 qDebug()<<"Inside FBRequest::cancel()"; |
|
379 } |
|
380 |
|
381 |
|
382 void FBRequest::call (const QString& aMethod, const Dictionary& aParams) |
|
383 { |
|
384 QByteArray dataParams; |
|
385 callWithDataParams(aMethod, aParams, dataParams, false); |
|
386 |
|
387 } |
|
388 |
|
389 void FBRequest::callWithDataParams (const QString& aMethod, const Dictionary& aParams, const QByteArray& aDataParam, bool aDataParamPicture) |
|
390 { |
|
391 Q_UNUSED(aParams) |
|
392 Q_UNUSED(aDataParam) |
|
393 Q_UNUSED(aDataParamPicture) |
|
394 iUrl = urlForMethod(aMethod); |
|
395 iUrl += aMethod; |
|
396 qDebug()<<"URL inside call with Data Params"<<iUrl; |
|
397 //iMethod = aMethod; |
|
398 //iParams = aParams; |
|
399 /* iParams["oauth_nonce"] = iSession->stroauth_nonce; |
|
400 iParams["oauth_signature_method"] = "HMAC-SHA1"; |
|
401 iParams["oauth_timestamp"] = iSession->stroauth_timestamp; |
|
402 iParams["oauth_consumer_key"] = kConsumerKey; |
|
403 iParams["sig"]=iSession->stroauth_signature; |
|
404 iParams["oauth_version"] = "1.0";*/ |
|
405 //iDataParam = aDataParam; |
|
406 // iDataParamPicture = aDataParamPicture; |
|
407 |
|
408 // iParams["method"] = iMethod; |
|
409 // iParams["api_key"] = iSession->apiKey(); |
|
410 // iParams["v"] = kAPIVersion; |
|
411 // iParams["format"] = kAPIFormat; |
|
412 |
|
413 /* if (!isSpecialMethod()) |
|
414 { |
|
415 iParams["session_key"] = iSession->sessionKey(); |
|
416 iParams["call_id"] = generateCallId(); |
|
417 |
|
418 if (iSession->sessionSecret().length()) |
|
419 { |
|
420 iParams["ss"] = "1"; |
|
421 } |
|
422 }*/ |
|
423 |
|
424 // XXX: workaround what seems to be a Qt bug with the extras-devel libraries. |
|
425 // QString signature = generateSig(iParams); |
|
426 // iParams["sig"] = signature; |
|
427 // XXX: end workaround. |
|
428 |
|
429 iSession->send(this); |
|
430 } |
|
431 |
|
432 |
|
433 QVariant FBRequest::parseXMLResponse ( const QByteArray& aResponseData, FBError& aError) |
|
434 { |
|
435 qDebug()<<"Inside FBRequest::handleResponseData()"; |
|
436 QXmlInputSource input; |
|
437 input.setData(aResponseData); |
|
438 |
|
439 FBXMLHandler handler; |
|
440 QXmlSimpleReader parser; |
|
441 parser.setContentHandler(&handler); |
|
442 bool result = parser.parse(&input); |
|
443 |
|
444 QVariant rootObject = handler.rootObject(); |
|
445 |
|
446 if (handler.parseError() || !result) |
|
447 { |
|
448 aError.setCode( FBRESPONSE_PARSE_ERROR ); |
|
449 aError.setDescription("parser was unable to parse the xml response from facebook server."); |
|
450 |
|
451 return QVariant(); |
|
452 } |
|
453 else if (handler.rootName().compare("error_response")==0) |
|
454 { |
|
455 QVariantHash errorDict = rootObject.toHash(); |
|
456 |
|
457 bool result; |
|
458 int errorCode = errorDict.value("error_code").toInt(&result); |
|
459 |
|
460 aError.setCode( errorCode ); |
|
461 aError.setDescription( errorDict.value("error_msg").toString() ); |
|
462 |
|
463 return rootObject; |
|
464 } |
|
465 else |
|
466 { |
|
467 return rootObject; |
|
468 } |
|
469 |
|
470 } |
|
471 |
|
472 /////////////////////////////////////////////////////////////////////////////////////////////////// |
|
473 // instance provate slots |
|
474 void FBRequest::networkReplyError ( QNetworkReply::NetworkError aCode ) |
|
475 { |
|
476 emit requestFailedWithNetworkError(aCode ); |
|
477 } |
|
478 |
|
479 void FBRequest::networkReplyFinished () |
|
480 { |
|
481 qDebug()<<"Inside FBRequest::networkReplyFinished()"; |
|
482 QNetworkReply* reply = static_cast<QNetworkReply*> ( sender() ); |
|
483 QByteArray responseData = reply->readAll(); |
|
484 if(responseData != "") |
|
485 { |
|
486 qDebug()<<"response data:"<<responseData; |
|
487 QList<QByteArray>MyString = responseData.split('&'); |
|
488 QList<QByteArray>token = MyString[0].split('='); |
|
489 qDebug()<<token.at(1); |
|
490 iSession->stroauth_Token=token.at(1); |
|
491 QList<QByteArray>token_secret = MyString[1].split('='); |
|
492 qDebug()<<token_secret.at(1); |
|
493 iSession->stroauth_TokenSecret=token_secret.at(1); |
|
494 |
|
495 qDebug()<<"iSession->stroauth_Token"<<iSession->stroauth_Token; |
|
496 if(iSession->stroauth_Token != "") |
|
497 { |
|
498 emit LoadLoginPage(); |
|
499 qDebug()<<"Signal:LoadLoginPage() is emitted"; |
|
500 } |
|
501 } |
|
502 } |
|
503 void FBRequest::networkReplyFinishedNew () |
|
504 { |
|
505 qDebug()<<"Inside FBRequest::networkReplyFinishedNew()"; |
|
506 QNetworkReply* reply = static_cast<QNetworkReply*> ( sender() ); |
|
507 QByteArray responseData = reply->readAll(); |
|
508 if(responseData != "") |
|
509 { |
|
510 qDebug()<<"response data:"<<responseData; |
|
511 QList<QByteArray>MyString = responseData.split('&'); |
|
512 QList<QByteArray>token = MyString[0].split('='); |
|
513 qDebug()<<token.at(1); |
|
514 iSession->stroauth_Token=token.at(1); |
|
515 QList<QByteArray>token_secret = MyString[1].split('='); |
|
516 qDebug()<<token_secret.at(1); |
|
517 iSession->stroauth_TokenSecret=token_secret.at(1); |
|
518 |
|
519 qDebug()<<"iSession->stroauth_Token"<<iSession->stroauth_Token; |
|
520 qDebug()<<"iSession->stroauth_TokenSecret"<<iSession->stroauth_TokenSecret; |
|
521 iSession->save(); |
|
522 } |
|
523 } |
|
524 void FBRequest::connect_req(QString uri) |
|
525 { |
|
526 qDebug()<<"Inside FBRequest::connect_req()"; |
|
527 |
|
528 QNetworkRequest request; |
|
529 |
|
530 QSslConfiguration config( QSslConfiguration::defaultConfiguration() ); |
|
531 request.setSslConfiguration( config ); |
|
532 QUrl myurl; |
|
533 QString Authorization; |
|
534 if(uri == "/request_token") |
|
535 { |
|
536 myurl = kRequestTokenUrl; |
|
537 Authorization = "OAuth oauth_nonce=\"" + iSession->stroauth_nonce + "\", oauth_signature_method=\"HMAC-SHA1\", oauth_timestamp=\"" + iSession->stroauth_timestamp + "\", oauth_consumer_key=\"" + kConsumerKey + "\", oauth_signature=\"" + iSession->stroauth_signature.toAscii().toPercentEncoding() + "\", oauth_version=\"1.0\""; |
|
538 } |
|
539 else |
|
540 { |
|
541 myurl = kAccessTokenUrl; |
|
542 Authorization = "OAuth oauth_nonce=\"" + iSession->stroauth_nonce + "\", oauth_signature_method=\"HMAC-SHA1\", oauth_timestamp=\"" + iSession->stroauth_timestamp + "\", oauth_consumer_key=\"" + kConsumerKey + "\", oauth_token=\"" + iSession->stroauth_Token + "\", oauth_verifier=\"" + iSession->stroauth_verifier + "\", oauth_signature=\"" + iSession->stroauth_signature.toAscii().toPercentEncoding() + "\", oauth_version=\"1.0\""; |
|
543 } |
|
544 request.setUrl(myurl); |
|
545 |
|
546 |
|
547 qDebug()<<"myurl:"<<myurl; |
|
548 qDebug()<<"Authorization: "<<Authorization; |
|
549 QByteArray auth = Authorization.toUtf8(); |
|
550 qDebug()<<"auth:"<<auth; |
|
551 request.setRawHeader("Authorization",auth); |
|
552 const QString contentType = "multipart/form-data; boundary=" + kStringBoundary; |
|
553 request.setHeader (QNetworkRequest::ContentTypeHeader, contentType); |
|
554 |
|
555 QByteArray postBody ; |
|
556 generatePostBody (postBody); |
|
557 postBody = ""; |
|
558 pbar = new progressbar; |
|
559 pbar->show(); |
|
560 proxysettings(); |
|
561 QNetworkReply* reply = iNetworkAccessManager.post(request, postBody); |
|
562 |
|
563 QObject::connect(reply, SIGNAL(finished()), this, SLOT(networkReplyFinishedNew())); |
|
564 QObject::connect(reply, SIGNAL(error(QNetworkReply::NetworkError)),this, SLOT(networkReplyError(QNetworkReply::NetworkError))); |
|
565 |
|
566 |
|
567 } |