문제

I'm working on a web service based system which has a Client who encrypts a text using DES algorithm.

When my client sends the encrypted text to a web method on the web service, I catch a

ProtocolException exception saying The remote server returned an unexpected response: (400) Bad Request.

Text before encryption : "Hello"
Text after encryption : "I%�l�*�"

What should I do to solve the issue?

도움이 되었습니까?

해결책

Exception occurred due to special characters in string which is not supported. You can make change in service to accept stream in place of string.

Server side code :

Boolean GetData(Stream fStream)
{
    try 
    {           
    // Read the stream into a byte array

    Byte[] data  = new Byte[32767];
    using (MemoryStream ms = new MemoryStream())
    {
            while(true)
            {
                    Int32 read = stream.Read(data, 0, data.Length);
                    if(read <= 0)
                        return ms.ToArray();
                    ms.Write(data, 0, read);
            }
    }

    // Copy to a string for header parsing
    String content = Encoding.UTF8.GetString(data);

    // do something
    }
    catch (Exception ex)
    {
    throw(ex);
    }
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top