Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 2005 > C# 2005
|
C# 2005 For discussion of Visual C# 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# 2005 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 4th, 2007, 04:51 PM
Registered User
 
Join Date: Oct 2007
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default Sending Trackback To A Blog With c#

i am facing a liitle problem. i think
anyone can help me. i am trying to send
trackback to a blog from a c# application.
when i send trackback reply from blog
shows that it gets the trackback. but
nothing is posted in the blog.
 here is my piece of code which actully
performing this. i hope someone can
figure out problem what i am doing wrong.

///url=url of the post which sends trackback
//blog name=name of the blog which sends trackback
//tburl=url to which trackback will be send
//title=title of the trackback
//excerpt=comments

void SendTrackBck(string url,string title,string blog_name,string excerpt,string tburl)
{
try
            {
                string szTrackbackUrl = tbUrl;
                HttpWebRequest hwrTrackback = (HttpWebRequest)WebRequest.Create(szTrackbackUrl);

                hwrTrackback.Method = "POST";

                StringBuilder sbFormData = new StringBuilder ();
                sbFormData.AppendFormat("url={0}", HttpUtility.UrlEncode(url));
                sbFormData.AppendFormat ("&title={0}", HttpUtility.UrlEncode (title));
                sbFormData.AppendFormat ("&blog_name={0}", HttpUtility.UrlEncode (blog_name));
                sbFormData.AppendFormat ("&excerpt={0}", HttpUtility.UrlEncode (excerpt));

                hwrTrackback.ContentType = "application/x-www-form-urlencoded";
                hwrTrackback.KeepAlive = false;

                byte [] abFormData = System.Text.Encoding.UTF8.GetBytes (sbFormData.ToString ());
                hwrTrackback.ContentLength = abFormData.Length;

                Stream strFormData = hwrTrackback.GetRequestStream ();
                strFormData.Write (abFormData, 0, abFormData.Length);
                strFormData.Close ();

                HttpWebResponse hwrResponse = (HttpWebResponse) hwrTrackback.GetResponse ();



                Stream stream = hwrResponse.GetResponseStream();

                StreamReader reader = new StreamReader(stream);

                string read = reader.ReadToEnd();

                reader.Close();
                stream.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show (ex.ToString ());
            }
}


thanks
rashed
 
Old October 6th, 2007, 08:45 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

The code looks fine.

Are you sure that the receiving system allows or displays trackbacks? Perhaps the trackbacks are moderated and are not displaying immediately?

Have you actually looked at the response string to see what they send back? maybe that would give you a clue.

/- Sam Judson : Wrox Technical Editor -/
 
Old October 6th, 2007, 03:22 PM
Registered User
 
Join Date: Oct 2007
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Sam
 thanks for your reply.

actually the receiving site
allows trackbacks and
response from site indicates
that it receives the trackback.

i have actually no idea why it
is not working.

 i am trying it with my blog
rkzico.wordprss.com. i hope
you can help me to make it work.

thanks
rashed

 
Old October 6th, 2007, 04:45 PM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

Are you sure the default theme on wordpress is set up to show trackbacks?

/- Sam Judson : Wrox Technical Editor -/
 
Old October 7th, 2007, 12:23 PM
Registered User
 
Join Date: Oct 2007
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

actually i can send trackback
to it with a php script.
but i need to do it in c#

thanks
zico
 
Old October 7th, 2007, 03:40 PM
Registered User
 
Join Date: Oct 2007
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thanks sam for take a look at my problem

i made it work.

i just changed the following lines


///
  byte [] abFormData = System.Text.Encoding.UTF8.GetBytes (sbFormData.ToString ());

to

byte [] abFormData = System.Text.Encoding.ASCII.GetBytes (sbFormData.ToString ());

and


///
Stream strFormData = hwrTrackback.GetRequestStream ();
                strFormData.Write (abFormData, 0, abFormData.Length);
                strFormData.Close ();


to

using (Stream strFormData = hwrTrackback.GetRequestStream())
                {
                    strFormData.Write(abFormData, 0, abFormData.Length);
                }

thanks
rashed
 
Old October 8th, 2007, 05:14 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

And alternative might have been to set the charset of the request:

Code:
hwrTrackback.ContentType = "application/x-www-form-urlencoded; charset=utf-8";
/- Sam Judson : Wrox Technical Editor -/
 
Old October 9th, 2007, 01:36 PM
Registered User
 
Join Date: Oct 2007
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thanks sam.

i will also check your solution.

rashed





Similar Threads
Thread Thread Starter Forum Replies Last Post
Wrox Blog in C# madAlan BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 22 June 12th, 2011 04:09 AM
import blog kumiko Classic ASP Basics 1 July 30th, 2008 01:53 PM
Wrox Blog tblessed23 BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 16 May 14th, 2007 04:08 PM
Wrox Blog: Viewing individual blog entries Tawanda BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 7 May 7th, 2007 12:06 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.