2011-05-20 104 views
0

我已經創建了一個電子書閱讀器應用程序&它支持應用程序內購買。將生成的交易收據發送給jboss服務器。已經編寫了下面的一段代碼來將交易收據發送給服務器。在這裏我將.xml文件轉換爲NSdata &將NSdata對象傳遞給服務器。應用內購買發送交易回執到服務器

-(IBAction)download:(id)sender{ 
    NSString *XMLPath = [[NSBundle mainBundle] pathForResource:@"ebook" ofType:@"xml"]; 

    NSString *name = @"photo1"; 
    NSData *imageData = [NSData dataWithContentsOfFile:XMLPath]; 
    NSLog(@"size of imageDATA %d",imageData.length); 
    //NSString *Datastring = [NSString strin] 
    NSString *dataString = [[NSString alloc] initWithData:imageData encoding:NSUTF8StringEncoding]; 
    //transaction.transactionReceipt; 
    //NSData * imageData = UIImagePNGRepresentation(image); 
    // NSString *postLength = [NSString stringWithFormat:@"%d", [imageData length]];   
    NSString *urlString = @"http://172.18.11.162:8080/DRM_15April/ReceiptDownload"; 
    //urlString = [urlString stringByAppendingString:@"tranReceipt"]; 
    //urlString = [urlString stringByAppendingString:@"&name="]; 
    //urlString = [urlString stringByAppendingString:name]; 
    //urlString = [urlString stringByAppendingString:@"&lang=en_US.UTF-8"]; 
    NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease]; 
    [request setURL:[NSURL URLWithString:urlString]]; 
    NSLog(@"the url is %@",urlString); 
    [request setHTTPMethod:@"POST"]; 
    NSMutableData *postBody = [NSMutableData data]; 



    //add data field and file data 
    [postBody appendData:[NSData dataWithData:imageData]]; 
    NSLog(@"size of DATA %d",postBody.length); 
    // --------- 

    [request setHTTPBody:postBody]; 

    // now lets make the connection to the web 
    NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil]; 
    NSString *returnString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding]; 

    NSLog(@"return strind is %@",returnString); 

} 

這是在我的控制檯窗口中記錄以下內容。

-[KitabooBookShelf download:] the url is http://172.18.11.162:8080/DRM_15April/ReceiptDownload 
(1) -[KitabooBookShelf download:] size of DATA 364 
(1) -[KitabooBookShelf download:] return strind is <html><head><title>JBossWeb/2.0.1.GA - Error report</title><style><!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR {color : #525D76;}--></style> </head><body><h1>HTTP Status 500 - </h1><HR size="1" noshade="noshade"><p><b>type</b> Exception report</p><p><b>message</b> <u></u></p><p><b>description</b> <u>The server encountered an internal error() that prevented it from fulfilling this request.</u></p><p><b>exception</b> <pre>java.io.StreamCorruptedException: invalid stream header: 3C3F786D 
    java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:782) 
    java.io.ObjectInputStream.&lt;init&gt;(ObjectInputStream.java:279) 
    com.hurix.drm.servlet.ReceiptDownload.doPost(ReceiptDownload.java:40) 
    javax.servlet.http.HttpServlet.service(HttpServlet.java:710) 
    javax.servlet.http.HttpServlet.service(HttpServlet.java:803) 
    org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198) 
    org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76) 
    com.hurix.drm.common.filter.SessionFilter.doFilter(SessionFilter.java:75) 
    org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96) 
</pre></p><p><b>note</b> <u>The full stack trace of the root cause is available in the JBossWeb/2.0.1.GA logs.</u></p><HR size="1" noshade="noshade"><h3>JBossWeb/2.0.1.GA</h3></body></html> 

任何人都可以建議我在我的應用程序端可能會出錯。

回答

1

您嘗試讀取與ObjectInputStream的XML數據,但隨着javadoc說:

的ObjectInputStream的反序列化的基本數據和對象以前使用ObjectOutputStream寫入。

所以實際上客戶端沒有錯,但在服務器端。

+0

服務器端可能出現什麼問題? – 2011-05-20 11:25:55

+0

我假設ReceiptDownload是你自己的servlet實現,對吧?在doPost裏面,你應該做XML解析,而不是用ObjectInputStream讀取 – 2011-05-20 11:47:45

+0

prob在服務器端.........我的應用程序運行完全正常 – 2011-05-20 14:41:01

相關問題