简体   繁体   中英

Guid field set to empty when requset API with junk characters

I have an API hosted on IIS Server.

I am making a request to a URI with below params.

{"CurrentTime":"2013-09-23 13:05:52",
"Measurement":[{"Comment":"Test Comment","RecordIdentifier":"7F54BF3C-6022-423B-8B8F-0121BA2AF516"}],
"Source":"ABC","Destination":"XYZ",
"FinalIdentifier":"058B5913-FAB9-4641-B02E-2729A02B5059"}

For the above request i can successfully deserialize the request parameters. Notice the value of "FinalIdentifier" and "Comment" parameter.

But, when Request like :

{"CurrentTime":"2013-09-23 13:05:52",
"Measurement":[{"Comment":"Âëīö","RecordIdentifier":"01CEBEAE-B99D-47B1-9C2D-1CB80069917B"}],
"Source":"ABC","Destination":"XYZ",
"FinalIdentifier":"058B5913-FAB9-4641-B02E-2729A02B5059"} 

I can also deserialize this request successfully but the value of "FinalIdentifier" parameter is getting Guid.Empty (00000000-0000-0000-0000-000000000000) . Here notice the Umlet characters in 2nd request for comment field, it is some German characters (junk characters).

So, does junk characters affect the GUID value ? But, also notice the Value of "RecordIdentifier" value in both request. It is not problem with "RecordIdentifier".

So where is the thing going wrong ?

I have below Entity for Request and parsing.

public class Measurement
{
    public string Comment { get; set; }
    public Guid RecordIdentifier { get; set; }
}
public class MeasurentEntityMain
{
    public List<Measurement> measurement { get; set; }
    public Guid FinalIdentifier { get; set; }
    public string Source { get; set; }
    public string Destination { get; set; }
}

Above both request i have captured from fiddler. and at API side i have tested it with debugging.

So, why this Guid field set to empty field.

I am using JSON serialization and deserialization.

I found the solution of the above said problem.

Actually i was checking Guid value at Controller side. And was getting Empty value.

I have created a HTTPhandler at my API side. This handler handles every request at routing time and then request is forwarded to respective APIController.

I have noticed at Handler side that for the Request with some Umlaut Characters, Some part of Requested data get truncated.

In Real Guid Field is of 32 Alphanumeric value and 4 dashes. But I was getting around 29 characters in Guid Value as it was last parameter in Request data some part was truncated.

When googled more i found that Umlaut characters with Length function returns length = 2.

So, For 3 Umlaut characters, 3 characters in Request data was getting truncated as i was using UTF8ENCODING and then Converting it To Byte data with Length of original string.

For more detail of this issue visit : iOS HttpRequest with umlaut has incorrect length

Thanks a lot SO.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM