日本黄色一级经典视频|伊人久久精品视频|亚洲黄色色周成人视频九九九|av免费网址黄色小短片|黄色Av无码亚洲成年人|亚洲1区2区3区无码|真人黄片免费观看|无码一级小说欧美日免费三级|日韩中文字幕91在线看|精品久久久无码中文字幕边打电话

當前位置:首頁 > 芯聞號 > 充電吧
[導讀]C++需要實現(xiàn)PHP端的:bin2Hex函數(shù),PHP通過這種類型的字符串調(diào)用:pack轉(zhuǎn)換成PHP能識別的2進制數(shù)據(jù)。 C++需要做的是實現(xiàn)一個bin2hex,其實只是把c++讀取的2進制數(shù)據(jù)當成b

C++需要實現(xiàn)PHP端的:

bin2Hex函數(shù),PHP通過這種類型的字符串調(diào)用:pack轉(zhuǎn)換成PHP能識別的2進制數(shù)據(jù)。

C++需要做的是實現(xiàn)一個bin2hex,其實只是把c++讀取的2進制數(shù)據(jù)當成byte數(shù)組,把每一位轉(zhuǎn)換成16進制字符串就可以了。Qt中使用sprintf無法限制2位長度,因此sprintf之后判斷長度為8則截取最后3個字符串,包含了/0終止符
#ifndef PHPCLASS_H
#define PHPCLASS_H

#include 

class PhpClass : public QObject
{
    Q_OBJECT
public:
    explicit PhpClass(QObject *parent = 0);

    //字節(jié)流轉(zhuǎn)換為十六進制字符串的另一種實現(xiàn)方式
    void Bin2Hex( const char *sSrc,QString& ret, int nSrcLen );

    //十六進制字符串轉(zhuǎn)換為字節(jié)流
    void Hex2Bin(  char* source, QByteArray& ret, int sourceLen);
signals:

public slots:
};

#endif // PHPCLASS_H

PhpClass::PhpClass(QObject *parent) : QObject(parent)
{

}



void PhpClass::Bin2Hex( const char *sSrc,QString& ret, int nSrcLen )
{

    int  i;
    char szTmp[3];

    for( i = 0; i < nSrcLen; i++ )
    {
        sprintf( szTmp, "%02X", (unsigned char) sSrc[i] );
        ret.append(szTmp);
    }
    return ;
}


void PhpClass::Hex2Bin(  char* source, QByteArray& ret, int sourceLen)
{

    int i;
    unsigned char highByte, lowByte;

    for (i = 0; i < sourceLen; i += 2)
    {
        highByte = toupper(source[i]);
        lowByte  = toupper(source[i + 1]);

        if (highByte > 0x39)
            highByte -= 0x37;
        else
            highByte -= 0x30;

        if (lowByte > 0x39)
            lowByte -= 0x37;
        else
            lowByte -= 0x30;

        ret.push_back((highByte << 4) | lowByte);
    }

    return ;
}
#ifndef FILECLASS_H
#define FILECLASS_H

#include 

class FileClass : public QObject
{
    Q_OBJECT
public:
    explicit FileClass(QObject *parent = 0);
    bool Read(char* file,QByteArray& ret);
    bool Write(char* file,QByteArray& data);

signals:

public slots:
};

#endif // FILECLASS_H

#include "fileclass.h"
#include
#include
FileClass::FileClass(QObject *parent) : QObject(parent)
{

}

bool FileClass::Read(char*file,QByteArray& ret)
{


    QFile mfile(file);
    if(!mfile.open(QIODevice::ReadOnly) )
    {

        qDebug()<<"文件不存在";
        return  false;
    }

    qDebug()<<"文件存在";
    ret = mfile.readAll();
    mfile.close();
    return  true;

}

 bool FileClass::Write(char* file,QByteArray& data)
 {

     QFile mfile(file);
     if(!mfile.open(QIODevice::ReadWrite) )
     {

         qDebug()<<"文件不存在";
         return false;

     }
     mfile.write(data);
     mfile.close();
     return  true;
 }

#include
#include
QVariant QmlClass::readimg(QString file)
{

    FileClass mfile;
    PhpClass  php;
    QByteArray  ar;
    QString m;
    if(mfile.Read((char*)file.toStdString().c_str(),ar))
    {

        php.Bin2Hex(ar.data(),m,ar.size());
        //2進制流轉(zhuǎn)16進制字符串方式1

        QByteArray dates;
        php.Hex2Bin((char*)m.toStdString().data(),dates,m.length());
        mfile.Write("./test.jpg",dates);
    }
    return m;
}
function uploadimg()
    {
        var  x = new XMLHttpRequest();

        x.onreadystatechange =function()
        {
            if(x.readyState == 4) {

                if(x.status == 200) {
                    console.log("The server replied with: " + x.responseText);
                    txt.text = x.responseText;

                }


            }
        };
        var xxx =new Object;
        var d=myapp.readimg(":/1.jpg");
        console.log(typeof d)
        x.open("POST","http://localhost/mycode/Test/reg.php",true);
        console.log(d)
        //post請求要自己設置請求頭
         x.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
        x.send(d);
    }
使用post參數(shù)和base64編碼:

    function uploadimg()
    {
        var  x = new XMLHttpRequest();

        x.onreadystatechange =function()
        {
            if(x.readyState == 4) {

                if(x.status == 200) {
                    console.log("The server replied with: " + x.responseText);
                    txt.text = x.responseText;

                }


            }
        };
        var xxx =new Object;
        var d=myapp.readimg(":/main.qml");
        console.log(typeof d)
        x.open("POST","http://localhost/mycode/Test/reg.php",true);
        console.log(Qt.btoa(d))
        //post請求要自己設置請求頭
         x.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
        x.send("OBJ="+Qt.btoa(d));
    }
本站聲明: 本文章由作者或相關機構授權發(fā)布,目的在于傳遞更多信息,并不代表本站贊同其觀點,本站亦不保證或承諾內(nèi)容真實性等。需要轉(zhuǎn)載請聯(lián)系該專欄作者,如若文章內(nèi)容侵犯您的權益,請及時聯(lián)系本站刪除( 郵箱:macysun@21ic.com )。
換一批
延伸閱讀
關閉