2013-03-18 41 views
2

我有一個ASP.net應用程序,允許用戶報告錯誤和附加文件。臭蟲及其細節和附件應保存在FogBugz中。 我已經設法創建除文件附件部分之外的所有內容。如何通過ASP.net應用程序將文件附加到FogBugz與C#

這裏是我的代碼:

private void NewCaseWithFile() 

    { 
     string fbUrl = "https://test.fogbugz.com/api.asp"; 
     string fbToken = logInFogBugz(); 
     string param = ""; 


     param += "cmd=new"; 
     param += "&token=" + fbToken; 


     param += "&sTags=" + "OnlineService,"; 
     param += "&sTitle=" + "Testing"; 

     param += "&sEvent=" + "This case is being created from Visual Studio"; 
     param += "&nFileCount=" + "1"; 
     param += "&File1=" + "Picture.png"; 


     HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(fbUrl + "?" + param); 
     httpWebRequest.Method = WebRequestMethods.Http.Post; 
     httpWebRequest.ContentType = "multipart/form-data"; 

     httpWebRequest.Accept = "application/xml"; 
     httpWebRequest.ContentLength = 0; 

     HttpWebResponse response = (HttpWebResponse)httpWebRequest.GetResponse(); 
     StreamReader streamReader = new StreamReader(response.GetResponseStream()); 
     XDocument doc = XDocument.Load(streamReader); 
    } 

我試圖在「Editing Cases」的所有指令,但它並沒有幫助。事實上,我不知道什麼是文件1,文件2以及如何將它們發送到FogBugz。

任何人都可以幫助我嗎? 非常感謝!

回答

0

應在多部分/表單數據文章的主體中指定File1(而不是查詢字符串參數)。

您實際上必須指定文件中的所有字節。

fogbugz.stackexchange.com以及C# FogBugz API wrapper有一個答案,將爲您處理所有部件。

在您的文章的身體形態的部分看起來像

--sdfjdsjsdflk SOME BOUNDARY-- 
Content-Disposition: form-data; name="File1"; filename="foo.jpg" 
Content-Transfer-Encoding: base64 
Content-Type: image/png 

slfkajdflksjflajfdj 
sldfjsd;aljfds 
these are actual data bytes from the foo.jpg file 
slfkjdsfljds 
sdflajsdfs 

或者你可以看看this question which points to an RFC用一個例子。

+0

雖然你的鏈接和示例是好的和有用的,你的文章似乎有點關閉。 – 2013-10-07 18:22:45

+0

蹩腳的評論系統;-) 雖然你的鏈接和樣本是好的和有用的,你的文章似乎有點關閉。 您的表單文章指定「base64」編碼;那麼你也應該在下面使用它。在這種情況下,數據將是: c2xma2FqZGZsa3NqZmxhamZkag0Kc2xkZmpzZDthbGpmZHMNCnRoZXNlIGFyZSBhY3R1YWwgZGF0YSBieXRlcyBmcm9tIHRoZSBmb28uanBnIGZpbGUNCnNsZmtqZHNmbGpkcw0Kc2RmbGFqc2Rmcw == 不過我遇到的FogBugz忽略的base64標誌和治療一切爲二進制的問題。可能是我的不好;-) – 2013-10-07 18:29:59