Sending a byte array from PHP to WCF

后端 未结 1 1956
Happy的楠姐
Happy的楠姐 2021-01-03 11:19

I have to send a byte array (encoded photo) from my PHP client to the WCF host. when I do a var_dump() on my array in PHP I get an array[2839] which is ok but on the server

相关标签:
1条回答
  • 2021-01-03 11:40

    You should use strings in PHP to emulate byte arrays. You can even use the syntax $str[index] with strings. You have a HUGE overhead (4x or 8x depending on the int size the payload PLUS the hash table overhead) otherwise.

    I'm not very familiar with the type conversions the SOAP extension does, but using a string instead will probably work.

    EDIT: Just checked the sources:

    if (Z_TYPE_P(data) == IS_STRING) {
        str = php_base64_encode((unsigned char*)Z_STRVAL_P(data), Z_STRLEN_P(data), &str_len);
        text = xmlNewTextLen(str, str_len);
        xmlAddChild(ret, text);
        efree(str);
    }
    

    So it already does the base 64 encoding for you.

    EDIT2: [SPECULATION]

    Your 5-byte long result is because of the conversion to string that follows the code above:

    if (Z_TYPE_P(data) == IS_STRING) {
            ...
    } else {
        zval tmp = *data;
    
        zval_copy_ctor(&tmp);
        convert_to_string(&tmp);
        str = php_base64_encode((unsigned char*)Z_STRVAL(tmp), Z_STRLEN(tmp), &str_len);
        text = xmlNewTextLen(str, str_len);
        xmlAddChild(ret, text);
        efree(str);
        zval_dtor(&tmp);
    }
    

    The conversion results in "Array", which is 5 bytes long.

    0 讨论(0)
提交回复
热议问题