|
I want to retrieve information from secured(requires user name and
password) web service. I can connect it with .NET using
NetworkCredentials class. But when I tried it with C++, I cannot even
send the username and password. I analyze the network activity with
Ethereal, the code doesn't send any authentication information. So the
server send HTTP 401 Authectication error back.
I'm searching web since last friday. I read and tried all I found.
What am i doing wrong?
Thanks for your help.
class CSampleBasicAuth : public CBasicAuthObject, public IAuthInfo
{
public :
void setUserName()
{
username = L"foo";
password = L"bar";
}
void Init(CAtlHttpClient *pSocket, IAuthInfo *pAuthInfo)
{
CBasicAuthObject::Init( pSocket, pAuthInfo );
}
bool Authenticate(LPCTSTR szAuthTypes, bool bProxy)
{
return CBasicAuthObject::Authenticate( szAuthTypes, bProxy );
}
HRESULT GetPassword(LPTSTR szPwd, DWORD* dwBuffSize)
{
if (CopyCString( password, szPwd, dwBuffSize ))
return S_OK;
return E_FAIL;
}
HRESULT GetUsername(LPTSTR szUid, DWORD* dwBuffSize)
{
if (CopyCString( username, szUid, dwBuffSize ))
return S_OK;
return E_FAIL;
}
HRESULT GetDomain(LPTSTR szDomain, DWORD* dwBuffSize)
{
ATLASSERT(false);
return S_OK;
}
CString username;
CString password;
};
...
void CWSdenemeDlg::OnBnClickedOk()
{
CString strMessage;
CoInitialize(NULL);
CWebService *ws = new CWebService();
ws->CleanupClient();
CAtlHttpClient &httpClient = ws->m_socket;
CSampleBasicAuth authObject;
authObject.setUserName();
httpClient.AddAuthObj(ATL_HTTP_AUTHTYPE_BASIC, &authObject,
&authObject);
bool val = httpClient.NegotiateAuth(true);
WSInputClass in;
in.member = ...
WSOutputClass* out = new WSOutputClass();
HRESULT hr = (HRESULT) ws->process(in, out);
if(FAILED(hr)){
switch(ws->GetClientError( ))
{
...
case SOAPCLIENT_SEND_ERROR :
strMessage="SOAPCLIENT_SEND_ERROR";
...
}
MessageBox(strMessage);
}
}
|
|
|
|
|
xelontr wrote: HTTP 401 Authectication
hum, are you sure you provide the correct Id + password there ? behaves as if you didn't
|
|
|
|
|
Yes, I send the right id and password. I also tried the web service with the HttpClient demo from Visual Studio. It is not working too. I didn't send any authentication information. I looked the network activity with Ethereal.
With .NET(C#) code I can see the authentication line in Ethereal, but with C++ no authentication line is seen.
Also there is strange thing in .NET. I discovered that the .NET code tries the web service twice(not tries it within code, in code the access to the web service was made once) First it tries without Authentication information, and server gives Authectication error(HTTP 401). Then it tries with Authentication information, and server returns successful message(HTTP 200).
I really doesn't understand anything.
Any idea
|
|
|
|
|
I solved the problem. The code is worked with the following line
httpClient.SetSilentLogonOk(true);
To send the password information out of the intranet SetSilentLogonOK method must be called.
Thanks
|
|
|
|
|
Hi all
I just want to know, what could be more complicated among these two topics..Stega(.JPG AND .MP3) or 3d Game Engine using Visual C++.
I am asking this because i am not that great programmer, i am learning and trying hard to bnecome good programmer but this is one thing which comes with practice.But project comes every yr. So i have to create a final yr project for my uni. Still time is there for about 6 months. So need to know what should be good option for me.
And if its stega then where should i start implementing it. Is there any book with C++ explaing the same or something similar.
Please guide me the right path.
Thanks a lot
|
|
|
|
|
there's an excelent series about steganography written around here by Corinna John[^], but it's in C#, so you'll have to adapt it if you still want it.
see here, in the security section[^] if you want the other articles by Corinna
|
|
|
|
|
I couldnt find any stega article for .JPG and .mp3?
Is there not any source code in C++ ?
Thanks for reply
|
|
|
|
|
Is there a way to prevent the "auto-scroll" when expanding a child in the CTreeCtrl ?
For example, if my item that I expand is near the bottom of the "view", and I expand it, it will scroll up to show the newly expanded children.
I checked the different Tree Window Styles, and nothing seems to be dealing with that.
Thanks.
|
|
|
|
|
Are you sure you wont care if the newly expanded children goes invisible as a result of stopping the scroll?
Dario: How is "directory" in French? (I mean a file system directory).
John Simmons: "zee file holdaire thingie"
|
|
|
|
|
hi
i m doing my proj in .net 2005.
i m passing string to a fuction in c++ called funt()
First the function is called from vb proj..
obj.funt(ByVal str As string).
but i dont know how to accept it in c++ funt().
plz help me
|
|
|
|
|
dalbhide bipin wrote: i m passing string to a fuction in c++ called funt()
are you already doing it or is it what you want to do ?
please show the code you've already tried if any
|
|
|
|
|
this is my form.vb file
i calling function_1939 from vb
obj.function_1939(ByVal str As string)
this is my classlibrary.. function_1939 is my function...
i want to accept the paramerters send thro VB
void Parse_J1939:: J1939 :: function_1939()
{
}
|
|
|
|
|
i understood that you already had some VB code.
what i want you is to tell me what you have already done for the C++ part...
|
|
|
|
|
actually my library code is too big..
i cant paste it here
this is my id..
dalbhidebipin@gmail.com
we can chat with each other...
if possible?
|
|
|
|
|
dalbhide bipin wrote: actually my library code is too big..
thanksfully, i don't want it ALL, it want it RELEVANT !
and i don't want your email, we are on a forum, it is to sare knowledges and solutions.
so i reiterate my question : will you please post a relevant piece of the C++ code that is about to get that parameter ?
and PLEASE use <pre></pre> tags around your code sample ; don't paste it like that
|
|
|
|
|
actully i confuse
what type of parameters should i accept..
char *, CString or any thing else
or give me a link.
so that i can read it by myself.
|
|
|
|
|
this is header file
#pragma once
#define _CRT_SECURE_NO_DEPRECATE
#include<iostream>
#include<cstring>
using namespace System;
namespace Parse_J1939
{
public ref class J1939
{
public:
void function_1939();
void protocol1939(int);
};
}
====================================================
#define _CRT_SECURE_NO_DEPRECATE
#include "stdafx.h"
#include "Parse_J1939.h"
#include
#include
#include
'#using
int a=0,b=0,c=0,d=0;
char line[128],copyofline[128];
int size = 63;
char address[12]={0};
char data_1939[5]={0};
char name_1939[5]={0};
//====================================================================================
void Parse_J1939:: J1939 :: function_1939()
{
int cnt = 63;
long command_in_int;
char *lineptr,*ptrtoline,*endptr;
char *ptr_for_strtol;
FILE *ptrtofile,*ptrtowritefile;
J1939 obj;
char command[]=" ";
char pduf[] = " ";
char destination[] = " ";
char source[] = " ";
const char str[2] = " ";
lineptr = &line[0];
ptrtowritefile = fopen("H:\\write.txt","w");
ptrtofile = fopen("H:\\source.txt","r");
fgets(line,cnt,ptrtofile);
strcat(line,"\n");
fputs(line,ptrtowritefile);
fgets(line,cnt,ptrtofile);
strcat(line,"\n");
fputs(line,ptrtowritefile);
fgets(line,cnt,ptrtofile);
strcpy(copyofline,line);
ptrtoline = strtok(lineptr,str);
|
|
|
|
|
if i remember well, BSTR is the correct type when dealing with VB codes
|
|
|
|
|
can u tell mi syntax..
or
tell me search topic so that i can search on it
|
|
|
|
|
can u tell the syntax
tell me
can i convert string (in vb ) to BSTR in vc++?
|
|
|
|
|
|
|
hi
i watching ur first link
its perfect 1
i hve question
should i add any header file for BSTR?
|
|
|
|
|
hi
i watching ur first link
its perfect 1
i hve question
should i add any header file for BSTR?
thanks
|
|
|
|
|
dalbhide bipin wrote: should i add any header file for BSTR?
Only if you want to be able to use a BSTR . Why would you unnecessarily add a header file?
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|